My input file stored in the txt format is some thing like:
data1 : 15 16 20 23 56
data2 : 15 65 89 64 65
so, I'm extracting the each line into string format into a separate files like below
Macro definition:
#define STRINGIFY_INIT(x) #x
#define STRINGIFY(x) STRINGIFY_INIT(x)
#define FILE_PREFIX data
#define FILE_EXT .txt
#define CONCAT_FILE(a) STRINGIFY(FILE_PREFIX) STRINGIFY(a) STRINGIFY(FILE_EXT)
Code Starts something like this:
std::string line;
std::ifstream readfile;
readfile.open("read.txt");
while(getline(readfile,line)){
int x = 1;
std::ofstream outputFile( CONCAT_FILE(x) );
outputFile << line <<std::endl;
std::cout<<line<<std::endl;
x++;
}
Now, this code creates the file called "datax.txt" and in the text file, it is the last extracted data from the inputfile is present.i.e,
data2 : 15 65 89 64 65
But, my requirement is it to create 2 files with name data1.txt and data2.txt, as there 2 lines of data present in the original input file.
The problem, I'm having is in the line:
std::ofstream outputFile( CONCAT_FILE(x) );
the expression "CONCAT_FILE(x) ", is not taking the value of x, but it is simply taking ASCII character "x".So, a single file with the name "datax.txt" is created and not "data1.txt","data2.txt".
I expected to work like, CONCAT_FILE(1) for the first iteration and CONCAT_FILE(2) for the next iteration, so that 2 files "data1.txt","data2.txt" are created.
Could any one please help me out.
I need to create 2 separate files, so that i can read only integer values separately and want to calculate mean for each of them.
Please do the needfull. Thanks,