Computer Science, asked by vrajthakkar2006, 5 months ago

write a c++ program to merge contents of two files into third file

Answers

Answered by Anonymous
0

Ways to Combine Two (or More) Text Files

  1. Right-click on the desktop or in a folder and choose New | Text Document from the resulting Context menu. ...
  2. Name the text document anything you like, such as "Combined. ...
  3. Open the newly created text file in Notepad.
  4. Using Notepad, open a text file you want combined.
  5. Press Ctrl+A. ...
  6. Press Ctrl+C.
Answered by Aayushimaurya2
0

Answer:

first create 3 files for merging

#include <iostream.h>

#include <stdlib.h> // For exit()  

#include <fstream.h>

#include <conio.h>

int main()

{

clrscr();

ifstream inf1("file1.txt",ios::in);

ifstream inf2;

inf2.open("file2.txt",ios::in);

ofstream outf;

outf.open("file3.txt",ios::out);

char c;

if (inf1.fail() || inf2.fail() || outf.fail())

{

cout<<"Could not open files";

exit(0);

}

while (!inf1.eof())

{

inf1.get(c);

outf.put(c);

}

while (!inf2.eof())

{

inf2.get(c);

outf.put(c);

}

outf.close();

cout<<"Merged file1.txt and file2.txt into file3.txt\n\n";

inf1.close();

inf2.close();

outf.close();

getch();

return 0;  

}  

Similar questions