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.
- Open the first file which contains data. For example, a file named “file1.txt” contains three strings on three separate lines “Programming Tutorials”, “By Geeks for geeks” and “Happy Coding!”.
- Open the second file to copy the data from the first file.
- Extract the contents of the first file line by line and write the same content to the second file named “file2.txt” via while loop.
- Extract the contents of the second file and display it via the while loop.
Programming Tutorials By Geeks for geeks Happy Coding!
My Personal Notes arrow_drop_up