PRACTICE • LEARN • GROW
Module 9 Final Quiz: File Handling (I/O Streams) MCQs
Solve topic-wise placement questions and improve your skills.
Module 9 Final Quiz: File Handling (I/O Streams) Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which header file must be included to work with file streams in C++?
A.
B.
C.
D.
Explanation & Key
Correct Answer:
2
Which stream class is specifically dedicated to reading files from disk?
A.
std::ofstream
B.
std::ifstream
C.
std::cin
D.
std::iostream
Explanation & Key
Correct Answer:
3
What happens by default when you open a file using 'ofstream out("data.txt");' if data.txt already exists?
A.
It appends new data to the end
B.
It truncates (completely erases) the previous file contents
C.
It raises a file_exists exception
D.
It opens the file in read-only mode
Explanation & Key
Correct Answer:
4
How do you verify whether a file opened successfully before attempting to read from it?
A.
if (file.ready())
B.
if (file.is_open())
C.
if (file == true)
D.
if (file.exists())
Explanation & Key
Correct Answer:
5
What function is used to read an entire line of text including spaces from an ifstream until a newline character is encountered?
A.
file.scan()
B.
std::getline(file, str)
C.
file >> str
D.
file.read_line()
Explanation & Key
Correct Answer:
6
What is the key difference between text mode and binary mode (ios::binary) file handling?
A.
Text mode is faster than binary mode
B.
Text mode performs newline character translation (\r\n <-> \n); binary mode writes and reads exact raw byte representations without any translation
C.
Binary mode only works on integers
D.
Text mode encrypts file contents
Explanation & Key
Correct Answer:
7
Which methods are used for raw binary reading and writing in C++ file streams?
A.
stream.push() and stream.pop()
B.
stream.write() and stream.read()
C.
stream.put_bytes() and stream.get_bytes()
D.
stream.send() and stream.recv()
Explanation & Key
Correct Answer:
8
What operator is used to write formatted data into an ofstream?
A.
>>
B.
<< (insertion operator)
C.
->
D.
=>
Explanation & Key
Correct Answer:
9
What mode flag should be passed to open a file for appending without overwriting existing data?
A.
std::ios::in
B.
std::ios::app
C.
std::ios::trunc
D.
std::ios::ate
Explanation & Key
Correct Answer:
10
Why is it generally safe to omit an explicit 'file.close()' call at the end of a function in modern C++?
A.
Operating systems automatically close files every minute
B.
The stream destructor automatically calls close() when the stream object goes out of scope (RAII)
C.
File streams never need to be closed
D.
Because the compiler deletes the file
Explanation & Key
Correct Answer:
11
What function repositions the read pointer in an ifstream?
A.
seekp()
B.
seekg()
C.
tellp()
D.
rewind()
Explanation & Key
Correct Answer:
12
What does the method tellg() return?
A.
The total size of the hard drive
B.
The current position of the get (read) pointer in the input stream
C.
The error status of the file
D.
The number of lines read
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong