Reading a single data from one column

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!!
Hi tatai,

Im also beginner to C++. With my understandings I have written a code. It worked me. Please check it out and correct me if Iam wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>

using namespace 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;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <fstream>

int main(void) {
    const std::string data = "Hello";
    for(int i = 0; i < data.size(); ++i) {
        std::string fileName = "FILE_";
        fileName+=static_cast<char>(i) + '0';
        std::ofstream writeFile(fileName.c_str());
        writeFile << data[i];
        writeFile.close();
    }
    return 0;
}

Let the string data represent the data you would like to save to each file.
Topic archived. No new replies allowed.