(SOLVED) clearing a stringstream

Started by
2 comments, last by kVandaele 19 years, 10 months ago
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]
Advertisement
ss.str(""); ?
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.
and here I was thinking stringstream::str was only for output. I have much to learn, masta...

This topic is closed to new replies.

Advertisement