Help needed to generate two file and write data into

Apr 5, 2013 at 4:37pm
I try to write my data into two different files and i just use something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ofstream myfile;
myfile.open("phase 1.txt");
if (myfile.is_open())
{
	for(i=0;i<M; i++)
	{
       	    myfile<<arrayD[j][10*i];
	    myfile<<",";	   
   	}
	return 0;  
        myfile.close();
}
ofstream myfile1;
myfile1.open("phase 2.txt");
if (myfile1.is_open())
{
	for(i=0;i<M; i++)
	{
       	    myfile1<<arrayD[j][10*i];
	    myfile1<<",";	   
   	}
	return 0;  
        myfile1.close();
}


But it only generate the first file. Anyone know the reason, how should i modify this? Any help is appreciated.
Apr 5, 2013 at 4:41pm
You exit the function on line 10 so no code after it is executed.

You could also just simply write to both files at the same time in the first loop.
Last edited on Apr 5, 2013 at 4:41pm
Apr 5, 2013 at 5:27pm
Problem solved! thanks.
Topic archived. No new replies allowed.