PF - WK 10 - File Handling
PF - WK 10 - File Handling
PF - WK 10 - File Handling
Programming Fundamentals
Fall 2023
Course conducted by
Dr. Mohammad Imran
Assistant Professor
Dept. of Cyber Security
1
Week 10
CS111 – Programming Fundamentals 2
File
▪ File is a mechanism to permanently store data on computer’s
secondary memory (storage)
The path and name of the file to be opened, including the extension.
For files in same folder as the program, file name is enough.
Hello,
Hello, world!
CS111 – Programming Fundamentals 9
Hello, world!
Hello, world!
Second line…
CS111 – Programming Fundamentals 11
▪ Nothing!
▪ ios::app is a flag which tells the system to open the file for
appending
▪ If the file exists, then it is opened for writing and its contents remain
CS111 – Programming Fundamentals 14
▪ If the file was opened without using the ios::app flag, then the line
will simply be added to the top of the file
CS111 – Programming Fundamentals 15
▪ If the file was opened with the ios::app flag, then the line will be
added to the end of the file
CS111 – Programming Fundamentals 16
▪ Not allowed!
▪ You must always check for end of file using eof() when reading a
file