I’ve tried several things already,
std::stringstream m; m.empty(); m.clear();
both of which don’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For all the standard library types the member function
empty()is a query, not a command, i.e. it means ‘are you empty?’ not ‘please throw away your contents’.The
clear()member function is inherited fromiosand is used to clear the error state of the stream, e.g. if a file stream has the error state set toeofbit(end-of-file), then callingclear()will set the error state back togoodbit(no error).For clearing the contents of a
stringstream, using:is correct, although using:
is technically more efficient, because you avoid invoking the
std::stringconstructor that takesconst char*. But any compiler these days should be able to generate the same code in both cases – so I would just go with whatever is more readable.