In this post we will write a C++ program to copy data from one file to another file.

C++ program to copy data from one file to another file


C++ program to copy data from one file to another file.

#include<iostream>
#include<conio.h>
#include<fstream>
#include<process.h>

using namespace std;

int main()
{
    system("cls");
    char ch;

    ifstream add("Sample.txt");
    ofstream sec("Example.txt");

    if(!add)
    {
        std::cout<<"File opening error";
        getch();
        exit(0);
    }
    while(add)
    {
        add.get(ch);
        sec.put(ch);
    }

    std::cout<<"File has copied successfully";

    getch();
    return 0;
}



Output

File has copied successfully