CPP File Handling MCQ
Cpp MCQ- Home
- Tutorials
- Cpp
- File Handling
- Multiple Choice Question
(1) In C++ which file mode is used to empty the file ?
A) trunc
B) truncate
C) empty
D) delete
Explanation
ios::trunc file mode isused to delete all data from file. Means to empty the file.
(2) Which file mode goto eof each time before writing data in C++ ?
A) ate
B) app
C) out
D) in
Explanation
app append file opening mode move cursor to the end of file before every write operation.
(3) Which file writing mode write data at the end of file in C++ ?
A) out
B) in
C) app
D) append
Explanation
ios::app file mode is used to open file in append mode. It append data in file at after end of file.
(4) How many parameters of open() method in file handling using C++ ?
A) 1
B) 2
C) 4
D) 6
Explanation
There are two parameters accepts by fstream open method. First is file path and second one is file mode.
(5) Which of the following class is used to create file writing operation?
A) ofstream
B) ifstream
C) writestream
D) outstream
Explanation
ofstream (output stream) class is used to create file writing object. It belongs to fstream class.
(6) How many modes can be specified in opening file?
A) One
B) Two
C) Four
D) Multiple
Explanation
We can specify multiple modes/operations while opening files in C++.
(7) Which of the following mode is used to write at the end of file.
A) ios::in
B) ios::out
C) ios::ate
D) ios::app
Explanation
Append mode is used for appending data into the files. Appending mode is specified using ios::app in file opening statement.
(8) Which of the following types of file can be used for read/write operations in C++ ?
A) .dat
B) .doc
C) .txt
D) All
Explanation
We can write and read data from any type of file using cpp fstream functions.
(9) Which of the following mode is used for writing data to files?
A) ios::write
B) ios::in
C) ios::out
D) ios::beg
Explanation
ios::out is file output mode that is used to write data/output to the files on secondary storage.
(10) Which of the following file reading mode in C++ ?
A) ios::out
B) ios::in
C) ios::read
D) ios::ate
Explanation
ios::in is file input mode. This is used to read data from files.
(11) Which of following header file is used for file IO operations in C++ ?
A) iostream
B) stlib
C) conio
D) fstream
Explanation
fstream means file stream header file is used for input and output operations in file handling.