Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between stringstream clear and str

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.

like image 761
Mahesh Avatar asked Dec 09 '08 11:12

Mahesh


1 Answers

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.

like image 143
AlfaZulu Avatar answered Oct 05 '22 19:10

AlfaZulu