How do I iterate over cin line by line in C++?

后端 未结 4 797
别跟我提以往
别跟我提以往 2020-11-22 09:53

I want to iterate over std::cin, line by line, addressing each line as a std::string. Which is better:

string line;
while (getline         


        
4条回答
  •  情书的邮戳
    2020-11-22 10:17

    The first one.

    Both do the same, but the first one is much more readable, plus you get to keep the string variable after the loop is done (in the 2nd option, its enclosed in the for loop scope)

提交回复
热议问题