0
votes

I have got multiple text files, which i seprated from one text file , now i want to merge them with , seprated form but column with the sequence

data1.txt

A man in the park

A man in the ground

A man is running

data2.txt

Yes1

No1

Why not1

data3.txt

Yes2
No2
Why not2

data4.txt

Yes3
No3
Why not3

data5.txt

Yes4
No4
Why not4

How can I merge these data files into a comma separated values () file using ?

1,A man in the park,Yes1,Yes2,Yes3,Yes4
2,A man in the ground,No1,No2,No3,No4
3,A man is running,Why not1,Why not2,Why not3 , Why not4

I saw related questions about it but its not related to

1
okay let me update what i tried , but its not workingAHF

1 Answers

0
votes

Have you tried opening all the files at once and using one string for each input file?

unsigned int line_number = 1;
ifstream file1("data1.txt");
ifstream file1("data2.txt");
ifstream file1("data3.txt");
ifstream file1("data4.txt");
ifstream file1("data5.txt");
ofstream out("output.txt");

std::string input1;
std::string input2;
std::string input3;
std::string input4;
std::string input5;

getline(file1, input1);
getline(file2, input2);
getline(file3, input3);
getline(file4, input4);
getline(file5, input5);


out << line_number
    << ", " << input1
    << ", " << input2
    << ", " << input3
    << ", " << input4
    << ", " << input5
    << "\n";

The above code is the fundamentals. The reader and OP need to put code into the loop and add error checking. This is structured in "batch" mode where many related operations are clumped together.

Yes, the above code could be simplified, but it is for illustration purposes.