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

前端 未结 10 1451
情书的邮戳
情书的邮戳 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:12

    Take the input from a file. Then you will find that the while loop terminates when your program stops taking input. Actually cin stops taking input when it finds an EOF marker. Each input file ends with this EOF marker. When this EOF marker is encountered by operator>> it modifies the value of internal flag eofbit into false and consequently the while loop stops.

提交回复
热议问题