Program 12 (1)
Program 12 (1)
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
void main()
{
clrscr();
char file1[] = "file1.txt";
char file2[] = "file2.txt";
char mergedFile[] = "merged.txt";
ifstream fin1(file1);
ifstream fin2(file2);
ofstream fout(mergedFile);
if (!fin1)
{
cout << "Error opening file " << file1 << endl;
getch();
return;
}
if (!fin2)
{
cout << "Error opening file " << file2 << endl;
getch();
return;
}
if (!fout)
{
cout << "Error opening merged file for writing" << endl;
getch();
return;
}
char ch;
while (fin1.get(ch))
{
fout.put(ch);
}
while (fin2.get(ch))
{
fout.put(ch);
}
fin1.close();
fin2.close();
fout.close();
cout << "Files merged successfully into " << mergedFile << endl;
getch();
}