Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void merge(ifstream& input1, ifstream& input2, ofstream& output);
- // Precondition:
- // The input files are text files.
- // The input files have been opened.
- int main()
- {
- ifstream infile1, infile2;
- ofstream outfile;
- char inName1[13], inName2[13], outName[13];
- int next;
- cout << "Enter the first of two input file names: " << endl;
- cin >> inName1;
- cout << "Now a second input file name " << endl;
- cin >> inName2;
- cout << "Enter the output file name. " << endl << "WARNING: ANY EXISTING FILE WITH THIS NAME WILL" <<" BE ERASED." << endl;
- cin >> outName;
- //closing files prior to reopening them for display
- //must open file outName as an ifstream to read it.
- infile1.open(inName1);
- infile2.open(inName2);
- outfile.open(outName);
- //Output the content of inName1 in here
- cout << "Contents of file " << inName1 << " are: " << endl;
- //Output the content of inName2 in here
- cout << "Contents of file " << inName2 << " are: " << endl;
- //Output the content of outName in here
- cout << "Contents of merged file " << outName << " are:" << endl;
- infile1.close();
- infile2.close();
- outfile.close();
- return 0;
- }
- void merge(ifstream input1, ifstream input2, ofstream output)
- {
- while (!input1.eof() && !input2.eof()) {
- output >> input1;
- output << input2;
- }
- }
- // END The REAL merge
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement