I created a simple program that writes some text to two different text files. Could someone show me how to create a program that would retrieve the information from those two files, and put them in a single file, first the content of input1 and then the content of input2. I am really needing help learning how to do this.
Here is the program that I created that creates the two files.
#include <iostream>
#include <fstream>
#include <string>
int main()
{
usingnamespace std;
string input1;
ofstream fout("input1.txt");
fout<<"This is the first line in input1.txt.\n";
cout<<"The first line was added to input1"<<endl;
fout<<"This is the second line in input1.txt.\n";
cout<<"The second line was added to input1"<<endl;
fout<<"This is the third line in input1.txt.\n";
cout<<"The third line was added to input1"<<endl;
fout<<"This is the fourth line in input1.txt.\n";
cout<<"The fourth line was added to input1"<<endl;
fout.close();
fout.open("input2.txt");
fout<<"This is the first line in input2.txt.\n";
cout<<"The first line was added to input2"<<endl;
fout<<"This is the second line in input2.txt."<<endl;
cout<<"The second line was added to input2"<<endl;
fout<<"This is the third line in input2.txt."<<endl;
cout<<"The third line was added to input2"<<endl;
fout.close();
cin.get();
cin.get();
return 0;
}
I read it, but I don't understand it. I am needing a program that can open or read the content of input1 and create a single file, and then to do the same with input2, but have them both going to the same single file, instead of two different files.
If you did not understand a lot from the tutorial I am not quite sure you are going to understand this when I write it either. Let us try it for now though. I wrote a more general case, this will make you able to read contents of N files and add them to a single file in order. Suppose you have some preliminaries: