Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

c++ code of file handling

Rating
-
Sold
-
Pages
9
Grade
A
Uploaded on
18-01-2026
Written in
2024/2025

it has many exercises of file handling for beginners to advance

Institution
Course

Content preview

NAME : UROOJ ASGHAR KHAN
ENROLLMENT: 02-135242-006


Task 1: Backup System



You are tasked with creating a program to back up the library's catalog.
The program should copy
the contents of the main catalog file to a backup file, ensuring that the
library's data is securely
preserved in case of any unforeseen events.




Code:

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

int main(){
cout << "\nCatalog backup initiated..." << endl<<endl;
cout << "Opening output file \"catalog.txt\"" << endl;
ofstream onFile;

, onFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile << "Book Title, Author, ISBN \nThe Catcher in the Rye, J.D.Salinger,
9780316769488 \nTo Kill a Mockingbird, Harper Lee, 9780061120084";
cout << "Output file opened successfully" << endl;
onFile.close();

ifstream inFile;
string str;
cout << "\nOpening input file \"catalog.txt\"" << endl<<endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
while (getline(inFile, str)){
cout << str << endl;
}
cout << "\nInput file opened successfully" << endl;
inFile.close();

cout << "\nCopying content from output to input" << endl;
inFile.open("C:\\Users\\spring2018\\Desktop\\catalog.txt");
onFile.open("C:\\Users\\spring2018\\Desktop\\catalog_1.txt");

char ch;
while (inFile.get(ch)){
onFile.put(ch);
}
cout << "Copied successfully!\n " << endl;
cout << "Closing input file" << endl;
inFile.close();
cout << "input file closed successfully!\n\n";

cout << "Closing output file" << endl;
onFile.close();
cout << " output file closed successfully!\n";
system("pause");
return 0;
}

Output:

Written for

Course

Document information

Uploaded on
January 18, 2026
Number of pages
9
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
uroojkhan1

Also available in package deal

Get to know the seller

Seller avatar
uroojkhan1 Bahria university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 months
Number of followers
0
Documents
13
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions