Stringstream

I already know about stringstream and how you can use it as a variable type, but I don't know how to clear it.

1
2
3
4
5
stringstream v;
int w;
string numbers;
v << w;
numbers = v.str();


I know how to do this to turn w into a string, but every time I call v << w; it adds to v. I know why it does this, but I don't know how to clear it without re-declaring it every time I use it. Do I do v << endl; or what?
Try:
 
v.str(""); // clear buffer 

Also you may need to do this if a read failed:
1
2
v.clear(); // clear error
v.str(""); // clear buffer 

Thanks. This should work.
Topic archived. No new replies allowed.