stringstream usage
stupid idiot (16)
Nov 11, 2009 at 6:56pm UTC
hey guys
im having some problem with using the stringstream. Emtpying it or not i just can't reuse it..
briefly my code looks like this:
1 2 3 4 5
stringstream s;
s.str(readBuf);
...some estrades with sstream, it possibly can change it's content...
then I want to use it again but i just can't make it working, i have tried to empty like this.
1 2 3
s.str("" );
s.str(string());
s.str(readBuf2);
Last edited on Nov 11, 2009 at 6:58pm UTC
kempofighter (1116)
Nov 11, 2009 at 9:49pm UTC
Need a more complete example please. Show us a main function that we can compile that demonstrates the problem.
rocarvaj (1)
Nov 29, 2009 at 11:53pm UTC
Hi!, I had the same problem. I think I figured out what happens.
In order to reuse the streamstring you have to clear the error control state. For example, in your case:
1 2
s.clear();
s.str(readBuf);
The clear function is here: http://www.cplusplus.com/reference/iostream/ios/clear/
Good luck!
Topic archived. No new replies allowed.