How to signify no more input for string ss in the loop while (cin >> ss)

前端 未结 10 1458
情书的邮戳
情书的邮戳 2020-11-29 09:12

I used \"cin\" to read words from input stream, which like

int main( ){
     string word;
     while (cin >> word){
         //do sth on the input word         


        
10条回答
  •  星月不相逢
    2020-11-29 10:06

    Your code is correct. If you were interactively inputting, you would need to send a EOF character, such as CTRL-D.

    This EOF character isn't needed when you are reading in a file. This is because once you hit the end of your input stream, there is nothing left to "cin"(because the stream is now closed), thus the while loop exits.

提交回复
热议问题