c++ when will while(cin>>s) stop

后端 未结 2 346
悲&欢浪女
悲&欢浪女 2021-01-15 05:30

I\'m new to C++. I\'m sorry if this question is duplicated but I just can\'t find similar question.

very basic code:

string s;
while (cin >> s)         


        
2条回答
  •  迷失自我
    2021-01-15 06:12

    You can signal EOF via CTRL-D or CTRL-Z.

    Or, you can check for a particular string to break the loop, like below:

    string s;
    while (cin >> s)
      {
         if(s == "end")
              break;
         cout << s << endl;
      }
    

提交回复
热议问题