Alright so i have this assignment to do. The question is as follow's.
------------------------------Question------------------------------
Write a command line program titled joinTextFiles.cpp that concatenates the contents of several files into one file. For example, the following command line
joinTextFiles chapter1.txt chapter2.txt chapter3.txt book.txt
will create a long file titled book.txt that contains the contents of the files chapter1.txt, chapter2.txt, and chapter3.txt. The target file, the one containing the contents of the other three files, is always the last file specified on the command line.
------------------------------Example------------------------------
Im not sure about how to do this all in a single command line. Ive managed to get this done without creating a command line. My code is here.
#include <iostream> //header files needed for the function and vector
#include <string>
#include <fstream>
using namespace std;
int main() // declaration of all variables
{
string line;
fstream chapter_one ("chapter1.txt"); //open the 3 text files
fstream chapter_two ("chapter2.txt");
fstream chapter_three ("chapter3.txt");
ofstream book ("book.txt"); //creates book.txt
if (chapter_one.is_open()) //if file chapter_one opens
{
while (! chapter_one.eof() ) //while NOT end of chapter1.txt
{
getline (chapter_one, line); //get contents of chapter1.txt
book << line << endl; //output contents of chapter1.txt to book.txt
}
while (! chapter_two.eof() ) //while NOT end of chapter2.txt
{
getline (chapter_two, line); //get contents of chapter2.txt
book << line << endl; //output contents of chapter2.txt to book.txt
}
while (! chapter_three.eof() ) //while NOT end of chapter3.txt
{
getline (chapter_three, line); //get contents of chapter3.txt
book << line << endl; //output contents of chapter3.txt to book.txt
}
cout <<"The files chapter1.txt, chapter2.txt and chapter3.txt. have all been joined\ntogether and outputted in the file book.txt.\n";
}
else cout <<"Unable to open file.\n"; //user error message
chapter_one.close();
chapter_two.close();
chapter_three.close();
book.close();
return 0;
}
The problem is that i cant find a way to do it the way the question is asking for. I have searched the internet and cant find anything. Could i get some help on this please.