Skip to main content
GameDev.net gamedev.net
🔒 Locked

stringstream causing problems

Started by RealmRPGer Feb 1, 2006 at 8:19 PM 3 replies 450+ views
Original Post
RealmRPGer
RealmRPGer
I can't get stringstream to work correctly. It accepts the first input and ouput, but if I try to give it any input after that, it fails to work any longer. I did notice that if I always keep something in the buffer, it will still accept input and output. The problem arises by the fact that I sometimes want to clear the buffer (it reads in object files that contain things such as comments, which should be discarded). getline(iStream, input); sStream << input; sStream >> scratch; sStream >> item; getline(iStream, input); sStream << input; sStream >> scratch; sStream >> health; etc...
T1Oracle
T1Oracle
you can manually set the contents of the buffer with:

sStream.str()

To clear it you would type: sStream.str("");

The same function returns the current string contained in the buffer.
Programming since 1995.
SiCrane
SiCrane
If you consume the entire stringstream contents you'll need to clear() the status bits to restore the stream to a usable state.
MaulingMonkey
MaulingMonkey
Quote:
Original post by SiCrane
If you consume the entire stringstream contents you'll need to clear() the status bits to restore the stream to a usable state.


QFE. Consuming everything will cause the EOF bit to be set, thus good() to return false, thus all your further streaming operations to fail.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.