> result; std::cout ...">

Stringstream not accepting space?

I have the following code:

std::stringstream ss; ss << 1 << "abc"; std::string result; ss >> result; std::cout << result << std::endl; 

I see "1a" instead of "1a bc".

I read somewhere that I should have ss <stand :: noskip. But that does not help.

Any idea?

Thanks in advance.

+4
source share
2 answers
 std::getline(ss, result); 

or just get string

 result = ss.str(); 
+8
source
 //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; 
0
source

Source: https://habr.com/ru/post/1484587/


All Articles