C++ Program to Read Content From One File and Write it Into Another File Last Updated : 04 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Here, we will see how to read contents from one file and write it to another file using a C++ program. Let us consider two files file1.txt and file2.txt. We are going to read the content of file.txt and write it in file2.txt Contents of file1.txt: Welcome to GeeksForGeeks Approach: Create an input file stream object and open file.txt in it.Create an output file stream object and open file2.txt in it.Read each line from the file and write it in file2. Below is the C++ program to read contents from one file and write it to another file: C++ // C++ program to read contents from // one file and write it to another file #include<bits/stdc++.h> using namespace std; // Driver code int main() { // Input file stream object to // read from file.txt ifstream in("file1.txt"); // Output file stream object to // write to file2.txt ofstream f("file2.txt"); // Reading file.txt completely using // END OF FILE eof() method while(!in.eof()) { // string to extract line from // file.txt string text; // extracting line from file.txt getline(in, text); // Writing the extracted line in // file2.txt f << text << endl; } return 0; } Output: file1.txt GeeksforGeeks is a Computer Science portal for geeks. file2.txt GeeksforGeeks is a Computer Science portal for geeks. Comment More infoAdvertise with us Next Article C++ Program to Read Content From One File and Write it Into Another File I ishankhandelwals Follow Improve Article Tags : C++ Programs C++ C++ File Programs Practice Tags : CPP Similar Reads C++ Program to Copy the Contents of One File Into Another File Here, we will see how to develop a C++ program to copy the contents of one file into another file. Given a text file, extract contents from it and copy the contents into another new file. After this, display the contents of the new file. Approach:Open the first file which contains data. For example, 2 min read C++ Program to Copy One File into Another File To copy the text/contents of one file to another file, we should know the basics of reading and writing a text file in C++. To copy the file using C++, we read the contents of the source file and write it into the destination file. Steps to copy one file to another in C++: Create objects of ifstream 2 min read C++ program to append content of one text file to another Given source and destination text files. Append the content from the source file to the destination file and then display the content of the destination file.Example : Input : file.txt : "geeks", file2.txt : "geeks for" Output: file2.txt : "geeks for geeks" Method 1:Approach: Open file.txt in inputs 3 min read Reverse the content of a file and store it in another The article explains how to store the reverse of the first text file's data to a second text file. In this post, it has been assumed that there is no text in the first text file. So we will write some text in a first text file by passing data to reverse function and then in reverse function we will 3 min read How to Read and Write Arrays to/from Files in C++? In C++, an array is a collection of elements of the same type placed in contiguous memory locations. A file is a container in a computer system for storing information. In this article, we will learn how to read and write arrays to/from files in C++. Example: Input: Array = {1, 2, 3, 4, 5}Output: // 2 min read Like