1. stringstream
1.1 stringstream 基本用法
#include <bits/stdc++.h>
using namespace std;
signed main(){
stringstream stream;
int first, second;
stream << "456"; //插入字符串
stream >> first; //转换成int
cout << first << endl;
stream.clear(); //在进行多次转换前,必须清除stream
stream << true; //插入bool值
stream >> second; //提取出int
cout << second << endl;
return 0;
}
1.2 stringstream 分割单词
#include <bits/stdc++.h>
using namespace std;
signed main(){
string str, abc;
getline(cin, str);
stringstream ss(str);
cout << ss.str() << endl;
while(ss >> abc){
cout << abc << endl;
}
return 0;
}