Q:

C++ Program to read text file and write in another text file in File Handling

belongs to collection: C++ File Handling Solved Programs

0

Write a C++ Program to read text file and write in another text file in File Handling. Here’s simple Program to read text file and write in another text file in File Handling in C++ Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C++ Program to read text file and write in another text file in File Handling which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 

SOURCE CODE : :

/*  C++ Program to read text file and write in another text file in File Handling  */

#include<fstream>
#include<iostream>
using namespace std;

int main()
{
    cout<<"Text File 1 is going to created........\n";
    ofstream fout("C:\\Users\\acer\\Documents\\file4.txt"); //create a file to write

    cout<<"\nText File 1 is opened for writing........\n";
    ifstream fin("C:\\Users\\acer\\Documents\\file4.txt");
    fout<<"Welcome to CodezClub......!!";

    cout<<"\nWriting to Text File 1 is successfully completed........\n";
    fout.close();                            //closing the file

    cout<<"\n\nText File 2 is going to create........\n";
    fout.open("C:\\Users\\acer\\Documents\\file5.txt"); //create file to write

    char ch;

    cout<<"\nText File 2 is opened for writing........\n";
    while(fin) //loop wiill run till end of file
    {
        fin>>ch;       //reading data from file
        fout<<ch;       //writing data to file
    }

    cout<<"\nWriting to Text File 2 from File 1 is successfully completed.\n";

    fin.close();
    fout.close();

    return 0;
}

OUTPUT : :


/*  C++ Program to read text file and write in another text file in File Handling  */

Text File 1 is going to created........

Text File 1 is opened for writing........

Writing to Text File 1 is successfully completed........


Text File 2 is going to create........

Text File 2 is opened for writing........

Writing to Text File 2 from File 1 is successfully completed.

Process returned 0

Above is the source code for C++ Program to read text file and write in another text file in File Handling which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to Count Occurrence of Word using File... >>
<< C++ Program to Count Words Lines and Total Size us...