0% found this document useful (0 votes)
5 views

Merge File

Uploaded by

priya magesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Merge File

Uploaded by

priya magesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MERGE FILE

#include <iostream>

#include <fstream>

#include <cstdlib>

using namespace std

int main()

char c;

char f1[256], f2[256], f3[256];

ifstream x1, x2;

ofstream x3;

cout << "Enter the name of the 1st file: ";

cin >> f1;

cout << "Enter the name of the 2nd file: ";

cin >> f2;

cout << "Enter the name of the 3rd file: ";

cin >> f3;

x1.open(f1, ios::in);

x2.open(f2, ios::in);

x3.open(f3, ios::out);

if (!x1 || !x2 || !x3) {

cout << "One or more files cannot be opened." << endl;

exit(1);

x3 << "Contents of " << f1 << ":\n";

while (x1.get(c))
{

x3.put(c);

x3 << '\n';

x3 << "Contents of " << f2 << ":\n";

while (x2.get(c)) {

x3.put(c);

x3 << '\n';

x1.close();

x2.close();

x3.close();

cout << "Files merged successfully." << endl;

return 0;

You might also like