what is the difference between stringstream clear and str
-
20-08-2019 - |
Question
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.
Solution
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.
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow