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
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.
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.
The consecutive duplicates of the string can be removed using the unique() function provided in STL.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With