string - Getting the remainder of a stringstream c++ -


i have stringstream need first part out , remainder separate string. example have string "this car" , need end 2 strings: a = "this" , b = "is car".

when use stringstream first part using <<,then use .str() convert string of course gave me whole thing "this car". how can play how want?

string str = "this car";  std::stringstream ss; ss << str;  string a,b; ss >> a; getline(ss, b); 

edit: correction @cubbi:

ss >> >> ws; 

edit:

this solution can handle newlines in cases (such test cases) fails in others (such @rubenvb's example), , haven't found clean way fix it. i think @tacp's solution better, more robust, , should accepted.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -