Archived

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

ByteMe95

how to clear a stringstream object in stl????

Recommended Posts

ByteMe95    122
Ive looked to the vast reaches of the itnernet and from what I have seen there is practically absolutely no way to clear a stringstream object!!! How is that possible? Say i have a stringstream object A, and i use it in a loop. At the beginning of every loop I want to clear A so it doesnt accumulate when I extract the string wtih A.str() FRom what ive seen there is no way to clear the buffer, the only solution i have come up wtih is to declare A as a pointer and do A = new stringstream; before the use and delete A after the use is there no better way? ByteMe95::~ByteMe95() My S(h)ite

Share this post


Link to post
Share on other sites
Atavist    122
Umm. I might be wrong but are you allowed to:


stringstream ss;
//fill ss with junk
ss = "";


Then again maybe I''m out to lunch on this one...

Share this post


Link to post
Share on other sites
ByteMe95    122
wow, ive never seen so many replies so fast! thanks everyone

There was only one correct answer to my question, and the answer is.... drumroll please.......

ss.str("")!!
thanks fruny

thanks again to everyone else for trying
- Rob

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
ByteMe95    122
ziphnor, i find it funny that you said .clear() worked for you when all logic dictates it shouldnt, so did you actually TRY it and it did in fact work, or were you just assuming it would?

ByteMe95::~ByteMe95()
My S(h)ite

Share this post


Link to post
Share on other sites
Ziphnor    122
quote:

ziphnor, i find it funny that you said .clear() worked for you when all logic dictates it shouldnt



Im not a complete idiot you know
In my code i use a stringstream in some string to value conversions, sometimes i had a problem with the stringstream containing some garbage after retrieving the value.
Using clear solved that problem, but when i think about it, this might have been due to some error during a conversion that was reset by clear....( i thought the garbage was leftover stuff from the previous strings added to the stringstream).

So the situation is not the same at all, i apologize.
Just tested it, and neither clear() or flush() empties the stringstream, but ss.str("") does....
Again, im sorry if i mislead anybody.

[edited by - ziphnor on June 11, 2002 2:19:18 PM]

Share this post


Link to post
Share on other sites