习题3.5 实现从标准输入每次读入一行文本。然后改写程序,每次读入一个单词。
1.每次读入一个单词
#include<iostream> #include<string> using namespace std; int main(){ string word; int n=1; while(cin>>word){ cout<<n<<": "<<word<<endl; n++; } cout<<endl; system("pause"); return 0; }
2.每次读入一行文本
#include<iostream> #include<string> using namespace std; int main(){ string line; int n=1; while(getline(cin,line)){ cout<<n<<": "<<line<<endl; n++; } cout<<endl; system("pause"); return 0; }
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号