Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear the content in the String stream.? [duplicate]

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

like image 636
Balamurugan Avatar asked Aug 04 '11 10:08

Balamurugan


People also ask

How do I delete duplicates in streams?

You can use the Stream. distinct() method to remove duplicates from a Stream in Java 8 and beyond. The distinct() method behaves like a distinct clause of SQL, which eliminates duplicate rows from the result set.

How do you clear a string stream?

You can easily clear the content of a StringStream object by using the predefined ss. clear() function. The function will erase the data in the buffer and make the object empty.

How do you remove duplicates from a string in C++?

The consecutive duplicates of the string can be removed using the unique() function provided in STL.


1 Answers

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?

like image 76
Seb Holzapfel Avatar answered Sep 19 '22 18:09

Seb Holzapfel