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

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

    You can make a check for a special word in input. F.e. "stop":

    int main( ){
       string word;
    
       while (cin >> word){
          if(word == "stop")
              break;
    
          //do sth on the input word
       }
    
    // perform some other operations
    }
    

提交回复
热议问题