views:

804

answers:

3

I just wanted to know what's the difference between clear() and str("");

For example:

stringstream ss("Stack Overflow");

ss.clear();

ss.str("");

I wanted to know the underlying technical difference.

+10  A: 

clear() clears the error state flags in the stringstream. That is to say it sets the error state to goodbit(which is equal to zero).

str("") sets the associated string object to the empty string.

They actually do completely different things. The peculiar choice of names only make it sound as though they perform similar tasks.

fpsgamer
+2  A: 
void clear ( iostate state = goodbit ) //clears and sets error flag passed as parameter

string str ( ) const;          //to get value from string stream
void str ( const string & s ); //to set value to string stream
yesraaj
+1  A: 

here is the answer

Comptrol