can any one tell me how to clear the content of the stringstream..? i tried the following but it didnt work.
stringstream ss;
ss<<"bala"<<"murugan";
cout<<ss.str(); //Output balamurugan
ss.str().clear();
ss<<" hi";
cout<<ss.str();
// output is balamurugan hi
my required output is " hi" alone.. Pls tell me
What you're doing is clearing the string that is returned from the stringstream, not the internal string. You'll have to actually do the ss.str("")
See here: How do you clear a stringstream variable?
The "clear()" member function is inherited from ios and is used to clear the error state of the stream.
For clearing the contents of a stringstream, using:
stringstreamObject.str("");
Do this:
ss.str("");
This makes the stream empty!
精彩评论