通过调用库sstream中的stringstream类型来完成想要拆分操作:
#include
#include
#include
#include
using namespace std;
int main(){
vector intlist;
string str;
int word;
getline(cin,str);//从输入流中读入字符串,遇到回车结束
stringstream ss(str);
while(ss >> word){//>>遇到空格返回整型给word
intlist.push_back(word);
}
}
凌云萧萧