0% found this document useful (0 votes)
7 views3 pages

Expt 11 Printout

This document contains a C++ program that demonstrates how to copy the contents of a text file named 'original.txt' to a new file called 'copy.txt'. It uses ifstream to read the original file and ofstream to write to the new file, displaying a message upon successful completion. The program also handles file opening errors by printing an error message if the files cannot be accessed.

Uploaded by

dnyanesh.agale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Expt 11 Printout

This document contains a C++ program that demonstrates how to copy the contents of a text file named 'original.txt' to a new file called 'copy.txt'. It uses ifstream to read the original file and ofstream to write to the new file, displaying a message upon successful completion. The program also handles file opening errors by printing an error message if the files cannot be accessed.

Uploaded by

dnyanesh.agale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

11
Name : Dnyanesh Nandkishor Agale
Roll No. : 1

// C++ Program to demonstrate

// copying the content of a .txt file


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

int main()
{
string line;

// For writing text file


// Creating ofstream & ifstream class object

ifstream ini_file

{
"original.txt" // This is the original file
};

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
printf("Cannot read File");

// Closing file
ini_file.close();

out_file.close();
return 0;
}

Before :

Output :
Copy Finished
After :

You might also like