> result; std::cout ...">All geek questions in one placeStringstream 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.+4c ++ g ++Hei Jun 05 '13 at 8:29source share2 answers std::getline(ss, result); or just get string result = ss.str(); +8Forvever Jun 05 '13 at 8:31source share //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; 0Gowtham g Jan 17 '17 at 0:51source shareSource: https://habr.com/ru/post/1484587/More articles:How can I fill out the submit button with the image? - htmlHow to display images from a database in JSF - javaEWS: Appoitnment Item.Id.UniqueId is not permanent - .netsorting a specific property - code improvement - c #I would like to create SSL certificates for my test environment - sslHow to match ICompositeUserType - c #java unzip zipfile with Unicode file names - javaWhy doesn't the C # compiler only allow delegation types in the inverse type when passing a group of methods as a parameter? - c #MySQL row with table name - mysqlUnable to disable error reporting in OpenCart (PHP) - phpAll Articles
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.
std::getline(ss, result);
or just get string
string
result = ss.str();
//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;
Source: https://habr.com/ru/post/1484587/More articles:How can I fill out the submit button with the image? - htmlHow to display images from a database in JSF - javaEWS: Appoitnment Item.Id.UniqueId is not permanent - .netsorting a specific property - code improvement - c #I would like to create SSL certificates for my test environment - sslHow to match ICompositeUserType - c #java unzip zipfile with Unicode file names - javaWhy doesn't the C # compiler only allow delegation types in the inverse type when passing a group of methods as a parameter? - c #MySQL row with table name - mysqlUnable to disable error reporting in OpenCart (PHP) - phpAll Articles