You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
950 B

2 years ago
#include <iostream>
#include <sstream>
//注意如果使用stringstream,需要加入这个头文件,否则报
// c++ aggregate std::stringstream ss has incomplete type and cannot be defined
using namespace std;
/*
3
i am huanghai !
*/
int main() {
int a;
cin >> a;
//准备接收一个带空格的字符串
string b;
// 方法1
// getchar(); //如果输入的数据中存在多个空格的时候此方法无效需采用getline(cin,b)
// 方法2
getline(cin, b); //吃掉上一次输入后面的换行符
getline(cin, b); //读入有用的字符串数据
//字符串流,用于将带空格的字符串分割开,形成一个个不带空格的字符串
stringstream ss(b);
string word;
int cnt = 0;
while (ss >> word) {
cout << word << endl;
cnt++;
}
cout << cnt << endl;
return 0;
}