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.
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.
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.
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