write a c++ program to merge contents of two files into third file
Answers
Answered by
0
Ways to Combine Two (or More) Text Files
- Right-click on the desktop or in a folder and choose New | Text Document from the resulting Context menu. ...
- Name the text document anything you like, such as "Combined. ...
- Open the newly created text file in Notepad.
- Using Notepad, open a text file you want combined.
- Press Ctrl+A. ...
- Press Ctrl+C.
Answered by
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