Raman has some data in his laptop saved in two different files, but now he wants to combine the data in one file from these two files. Write a program to complete this task.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string file_first;
string file_second;
cout << "Enter the name and path to the first file ";
getline(cin, file_first);
cout << "Enter the name and path to the second file ";
getline(cin, file_second);
ofstream of_first(file_first, ios_base::binary | ios_base::app);
ifstream if_second(file_second, ios_base::binary);
if (!of_first || !if_second)
{
cout << "Error opening files" << endl;
return 1;
}
// combine the data in file_first
of_first<< if_second.rdbuf();
of_first.close();
if_second.close();
return 0;
}
Comments
Leave a comment