clearing stringstream

In the project i am working on I have 8 different files that i need to read in a process. The files are named data1.txt through data 8.txt. I decided to loop through them with something general like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
string filename;
  int fileNumber;
  std::stringstream ss;

  for(int i = 1; i <=8; i++){
	fileNumber = i;
	ss<<fileNumber;
        filename = "data" + ss.str() + ".txt";
//code where i process the files
//put this here to test output
cout<<filename;
cout<<

}


the problem i am having is that when it shows my out put it goes data1.txt data12.txt data123.txt and so on. I have tried clearing out the stringstream with things like
ss.str() = "";
ss.clear;
but nothing seems to work.
Im thinking maybe im trying to clear out teh wrong thing?, or maybe im putting it at the wrong spot. If you would like me to paste the entire code just let me know i i will.
To clear the string stream:

ss.str("");
i have tried that also and it does not work.
omg lol nvm. I moved it to a different spot and it worked like a charm. ty
Last edited on
Topic archived. No new replies allowed.