The following program accept 4 command line arguments. First argument ( argv[0] ) is assumed as program name. second and third arguments are file names to be merged. Last argument is the output file, to which the merged contents saved.
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
#include <process.h>
int main(int argc, char* argv[] )
{
char ch;
ifstream infile;
infile.open( argv[1] );
if( !infile )
{
cerr << "\nCan't open " << argv[1];
exit(-1);
}
ofstream outfile;
outfile.open( argv[3] );
if( !outfile )
{
cerr << "\nCan't open " << argv[3];
exit(-1);
}
while( infile )
{
infile.get(ch);
outfile.put(ch);
}
infile.close();
infile.open( argv[2] );
if( !infile )
{
cerr << "\nCan't open " << argv[2];
exit(-1);
}
while( infile )
{
infile.get(ch);
outfile.put(ch);
}
infile.close();
outfile.close();
return 0;
}
Hope that this is useful for you