Create a variable number of files

Hi guys!

I need to write a short script that creates a variable number of output files according to the conditions I set.
My problem is that my script only create the first output file (named "file 0"), even if the block of commands in which it should create the following ones is read several times (I already checked).

This is the block of codes I am referring to:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while ( getline(file_input, line) )
{
	if (i == 0)
	{
		name = "file " + to_string(file_counter);
		file_output.open (name.c_str());
	}
	file_output << "hi" << endl;
	i++;
	if (i == 10)
	{
		i = 0;
		file_counter++;
	}
}


As far as I know, whenever I call this command
file_output.open (name.c_str());
a new file is created, whose name is given by the string variable "name".

Why I only get "file 0" and not also "file 1", "file 2", etc...?
Seems like you have to close the file before you can open another one.

 
file_output.close()
Oops! You're right!
Thanks! ^_^"
Topic archived. No new replies allowed.