stringstream使用

来源:互联网 发布:私募股权基金 知乎 编辑:程序博客网 时间:2024/05/03 13:27

stringstream //字符类型转换

ostringstream s; //处理字符中间有空格

s << "hello world";//使用空格分隔的两个词语
string str;
str = s.str();//在这里,我试图得到hello world, 但是,只能得到hello
cout << str;


stringstream ssm;
string   mystr="456";
ssm << mystr;
int a=0;
ssm >> a;
mystr.clear;


a++;
cout << a;*/
//float price = 0;
//int quantity = 0;
//cout << "Enter price: ";
//getline(cin, mystr);
//stringstream(mystr) >> price;
//cout << "Enter Quantity: ";
//getline(cin, mystr);
//stringstream(mystr) >> quantity;
//cout << "Total price: " << price*quantity << endl;


/*string mystr;
cout << "What's you name?";
getline(cin, mystr);
cout << "Hello " << mystr << ".\n";
cout << "What is your favorite color?";
getline(cin, mystr);
cout << "I like " << mystr << "too!\n";
*/