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

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

    It helps me to terminate loop by hitting ENTER.

    int main() {
        string word;
        while(getline(cin,word) && s.compare("\0") != 0) {
            //do sth on the input word
        }
    
        // perform some other operations
    }

提交回复
热议问题