can anyone tell me how to clear the contents of the string stream ...? I tried the following, but it did not 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 of "hi" is one. Pls tell me
What you do is clear the string that is returned from the string, not the string inside . You really need to doss.str("")
ss.str("")
See here: How to clear a stringstream variable?
The "clear ()" function is inherited from ios and is used to clear the stream error state.
, :
stringstreamObject.str("");
:
ss.str("");
!