Files
python/TangDou/XiTi/Test.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

36 lines
950 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}