12.10 | 学习笔记

抽象一条流操作:

题目会给出未知行数的内容,每行会包含未知个数的字符串,对其进行处理,代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 string line,str;
 4 int main()
 5 {
 6     while(getline(cin,line)){
 7         stringstream sin;
 8         sin<<line;
 9         while(sin>>str){
10             cout<<str<<' ';
11         }
12         cout<<endl;
13     }
14     return 0;
15 }

运行结果:(Ctrl Z表示输入结束)

 

posted @ 2020-12-10 16:17  MissCold  阅读(65)  评论(0编辑  收藏  举报