Answer to Question #295723 in C++ for Varsha Chouhan

Question #295723

Write a program to copy the contents of one file to another

1
Expert's answer
2022-02-09T14:50:32-0500
#include <iostream>
#include <fstream>
using namespace std;
 
int main()
{
    string line;
    //For writing text file
    //Creating ofstream & ifstream class object
    ifstream ini_file {"original.txt"};
    ofstream out_file {"copy.txt"};
 
    if(ini_file && out_file){
 
        while(getline(ini_file,line)){
            out_file << line << "\n";
        }
 
        cout << "Copy Finished \n";
 
    } else {
        //Something went wrong
        cout << "Cannot read File";
    }
 
    //Closing file
    ini_file.close();
    out_file.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