stringstream usage

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
Need a more complete example please. Show us a main function that we can compile that demonstrates the problem.
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.