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

31 lines
771 B
C++
Raw 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> //istringstream 必须包含这个头文件
#include <string>
using namespace std;
int main() {
string source = "i an a boy";
// 声明一个字符串输入流
istringstream sin;
// 将字符串导入到sin输入流中
sin.str(source);
// 分离的方法1
string s;
while (sin >> s) {
cout << s << endl;
}
cout << "===============================" << endl;
// 重复使用必须先清空
sin.clear();
// 重新加载,准备二次输入,或者sin的重用
sin.str(source);
string a, b, c, d;
sin >> a >> b >> c >> d;
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
return 0;
}