String Stream Errors

I was wondering how to clear a string stream variable. Heres an example of what I'm using it for:
You save 2 files. The first named "Fileo.txt" and the second "Filet.txt". The first saves correctly but the second one saves as "Fileo.txt Filet.txt".
How can I clear the variable?
I use this method:
1
2
3
stringstream ss;
// ...
ss.str(""); // clears the stream 
Last edited on
For some reason it didn't work, it still saves as "Fileo.txt Filet"
That's strange. Tell me if this works
1
2
3
4
5
6
7
8
9
10
11
int main()
{
stringstream ss;
ss<<"hello"<<"world";
cout <<ss.str()<<endl;

ss.str("");

ss<<"blah";
cout <<ss.str()<<endl;
}
helloworld
blah

Does this work for you?
I'm using it to save a file, you name the first file, then the second. When it saves them it save incorrectly. I don't think it'll be easy to diagnose since the program is complex. I don't know but the code above might be different then what I need cause I'm saving a file instead of displaying it in a "cout".
There's no difference, you're still using a stringstream.
Last edited on
Topic archived. No new replies allowed.