string转int:
int a = 3; string tem="12";
stringstream ss;
ss << tem;
ss >> a;
//a会变为int类型12
int转string:
int a = 3; string tem="12";
stringstream ss;
ss << a;
ss >> tem;
//tem会变为string类型"3"
以空格为切割符的字符串切割:
string sentence="hello world";
string word;
stringstream ss;
ss<<sentence;
while(ss>>word){
cout<<word<<"\n";
}
//程序运行结果为:
hello
world