I have a column with 100 data like,
1
2
3
4
.
.
.
100
I want to store each data in a single file. like '1' will be store in 'FILE 1', '2' will be store in 'FILE 2' and so on!!
I am not able to understand the logic, how to use the FOR loop for this purpose!!
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
usingnamespace std;
int main()
{
ifstream infile;
ofstream outfile[5];
string name="file",j;
for(int i=0;i<5;i++)
{
j=static_cast<char>(i+49);//to convert 1,2,3,4,5 into character because ascii value for char value '1' is 49
name=name.append(j);// appending 1,2,3,4,5 to the file
outfile[i].open(name);
name="file";//reseting the file name to file
}
for(int i=0;i<5;i++)
{
outfile[i]<<i+1;//writing outputs to the files
}
infile.close();
outfile[5].close();
system("pause");
return 0;
}