Advertisement
MutahirA_

Untitled

Nov 11th, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void merge(ifstream& input1, ifstream& input2, ofstream& output);
  7. // Precondition:
  8. // The input files are text files.
  9. // The input files have been opened.
  10.  
  11.  
  12. int main()
  13. {
  14. ifstream infile1, infile2;
  15. ofstream outfile;
  16. char inName1[13], inName2[13], outName[13];
  17.  
  18. int next;
  19.  
  20. cout << "Enter the first of two input file names: " << endl;
  21. cin >> inName1;
  22.  
  23. cout << "Now a second input file name " << endl;
  24. cin >> inName2;
  25.  
  26. cout << "Enter the output file name. " << endl << "WARNING: ANY EXISTING FILE WITH THIS NAME WILL" <<" BE ERASED." << endl;
  27. cin >> outName;
  28.  
  29.  
  30. //closing files prior to reopening them for display
  31.  
  32. //must open file outName as an ifstream to read it.
  33. infile1.open(inName1);
  34. infile2.open(inName2);
  35. outfile.open(outName);
  36.  
  37.  
  38. //Output the content of inName1 in here
  39. cout << "Contents of file " << inName1 << " are: " << endl;
  40.  
  41. //Output the content of inName2 in here
  42. cout << "Contents of file " << inName2 << " are: " << endl;
  43.  
  44. //Output the content of outName in here
  45. cout << "Contents of merged file " << outName << " are:" << endl;
  46.  
  47. infile1.close();
  48. infile2.close();
  49. outfile.close();
  50. return 0;
  51. }
  52.  
  53. void merge(ifstream input1, ifstream input2, ofstream output)
  54. {
  55. while (!input1.eof() && !input2.eof()) {
  56. output >> input1;
  57. output << input2;
  58. }
  59. }
  60. // END The REAL merge
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement