What is the difference between a clean string and str

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

For example:

stringstream ss("Stack Overflow"); ss.clear(); ss.str(""); 

I wanted to know the main technical differences.

+6
c ++ stringstream
source share
2 answers

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

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

They actually do completely different things. The unusual choice of names only makes it sound like they are performing similar tasks.

+15
source share
 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 
+5
source share

All Articles