• Advertisement

Archived

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

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

This topic is 5735 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

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
Advertisement
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
quote:
Original post by ByteMe95
ss = "" produces compiler errors, i guess you cant do that with stringstreams



We''re talking about std::stringstream, not strstream, right ?


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
i am using stringstream yes
dont really know what strstream is or what the differences are

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

Share this post


Link to post
Share on other sites
Maybe try
ZeroMemory(stringObj, sizeof(StringStream))
This may work, or it may casuse your computer to freeze, I don''t know, use at your own risk.

Share this post


Link to post
Share on other sites
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
ss.clear();

The above works for me(using VS .NET and its own STL library), it empties a stringstream object.

Share this post


Link to post
Share on other sites
quote:
Original post by Ziphnor
ss.clear();

The above works for me(using VS .NET and its own STL library), it empties a stringstream object.

Erm... no it doesn''t, it clears the stream''s status flags, as Fruny said earlier. Do pay attention!


[ C++ FAQ Lite | ACCU | Boost | Python | Agile Manifesto! ]

Share this post


Link to post
Share on other sites
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
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

  • Advertisement