Answer to Question #180627 in C++ for JAI PRAKASH DWIVEDI

Question #180627

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.




1
Expert's answer
2021-04-12T21:25:46-0400
#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;
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS