Archived

This topic is now archived and is closed to further replies.

(SOLVED) clearing a stringstream

This topic is 4949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

it's surprisingly hard to clear something with a .clear() member function... but stringstream::clear clears the flags, does not reset the stringstream contents to nothing. The way I was doing it was first do a ss.seekp(0); and then overwrite the text. That's fine and works good enough, but only IF the text you overwrite with is longer than what you had in it before. But now i've gotten to an area where it's shorter (much). You could cheat and fill it with spaces (enough to make sure everything's gone) but that doesn't work if you're aligning text right (plus it's not the proper way to do it, for sure). I've tried flushing the string stream, ending it (that didn't even compile), clearing it, ignoring it... I'm fresh out of ideas, and the documentation on it is so unclear it's no help at all. [edited by - kVandaele on May 30, 2004 1:52:32 PM]

Share this post


Link to post
Share on other sites
If memory serves, stringstream::str(std::string) (approximate signature, I''m not trying to be rigorous!) sets the string that the stringstream performs operations on, thus given a stringstream ss, ss.str(""); should set this internal buffer to the empty string.

Share this post


Link to post
Share on other sites