Reputation: 143
I have the following code:
std::stringstream ss;
ss << 1 << "a b c";
std::string result;
ss >> result;
std::cout << result << std::endl;
I see "1a" instead of "1a b c".
I read somewhere that I should have ss << std::noskip. But it doesn't help.
Any idea?
Thanks in advance.
Upvotes: 12
Views: 20387
Reputation: 11
//Try using this for getting whitespace in string
string input;
cout<<"\nInput : "<<input;
getline(cin,input);
string result,label;
std::stringstream sstr(input);
while(sstr>>label){
result=result+label+" ";
}
cout<<"\nResult : "<<result;
Upvotes: 0
Reputation: 55887
std::getline(ss, result);
or, just get string
result = ss.str();
Upvotes: 15