File Handling In C Plus Plus — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on File Handling In C Plus Plus — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the function used to create a new file in C++?
Correct Answer: Option D — ofstream file()
Detailed Academic Explanation:
The correct answer is D: ofstream file() Let's break down why: Option A: create() - There isn't a standard C++ function called create() specifically for file creation. Option B: newFile() - Similarly, newFile() is not a built-in C++ function for file handling. Option C: fopen() - fopen() is a C function for file input/output, and while it *can* be used in C++, it's more common and idiomatic to use C++'s file stream classes. fopen() also requires you to specify a mode (like "w" for write) which determines if you want to create the file, overwrite it, or append to it. It's generally less type-safe than C++ streams. Option D: ofstream file() - This is the C++ way to create a new file. ofstream is a class from the C++ standard library designed for output file streams. By creating an object of type ofstream (e.g., ofstream file; ), you can automatically create a new file or open an existing one for writing (if the file doesn't exist, it will be created). You can then use the file object to write data to the file. For Example : ofstream myFile("filename.txt"); will create a file named "filename.txt" or overwrite if it already exist .
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which header file is required for file handling in C++?
Correct Answer: Option B — <fstream>
Detailed Academic Explanation:
<fstream> is the correct answer to “Which header file is required for file handling in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the function used to open a file in C++?
Correct Answer: Option A — open()
Detailed Academic Explanation:
open() is the correct answer to “What is the function used to open a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you close a file in C++?
Correct Answer: Option A — file.close()
Detailed Academic Explanation:
file.close() is the correct answer to “How do you close a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which mode is used to open a file for writing in C++?
Correct Answer: Option C — write
Detailed Academic Explanation:
write is the correct answer to “Which mode is used to open a file for writing in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax for writing data to a file in C++?
Correct Answer: Option C — file << data
Detailed Academic Explanation:
file << data is the correct answer to “What is the correct syntax for writing data to a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file has been successfully opened in C++?
Correct Answer: Option A — file.is_open()
Detailed Academic Explanation:
file.is_open() is the correct answer to “How do you check if a file has been successfully opened in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to read data from a file in C++?
Correct Answer: Option C — file >> data
Detailed Academic Explanation:
file >> data is the correct answer to “Which of the following is used to read data from a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the seekg() function do in C++ file handling?
Correct Answer: Option A — Sets the get position pointer
Detailed Academic Explanation:
Sets the get position pointer is the correct answer to “What does the seekg() function do in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to delete a file in C++?
Correct Answer: Option D — remove()
Detailed Academic Explanation:
remove() is the correct answer to “Which function is used to delete a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which file mode is used to open a file for reading and writing in C++?
Correct Answer: Option D — rplus
Detailed Academic Explanation:
rplus is the correct answer to “Which file mode is used to open a file for reading and writing in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if the end of a file has been reached in C++?
Correct Answer: Option C — file.eof()
Detailed Academic Explanation:
file.eof() is the correct answer to “How do you check if the end of a file has been reached in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to get the current position of the file pointer in C++?
Correct Answer: Option C — tellg()
Detailed Academic Explanation:
tellg() is the correct answer to “Which function is used to get the current position of the file pointer in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the ios::app flag in C++ file handling?
Correct Answer: Option B — Opens the file in append mode
Detailed Academic Explanation:
Opens the file in append mode is the correct answer to “What is the purpose of the ios::app flag in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to check if a file exists in C++?
Correct Answer: Option B — exists(file)
Detailed Academic Explanation:
exists(file) is the correct answer to “Which function is used to check if a file exists in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create a new file in C++?
Correct Answer: Option B — createFile()
Detailed Academic Explanation:
createFile() is the correct answer to “How do you create a new file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which file mode is used to open a file for reading only in C++?
Correct Answer: Option C — read
Detailed Academic Explanation:
read is the correct answer to “Which file mode is used to open a file for reading only in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file exists before opening it in C++?
Correct Answer: Option A — file.exists()
Detailed Academic Explanation:
file.exists() is the correct answer to “How do you check if a file exists before opening it in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a file stream class in C++?
Correct Answer: Option D — filestream
Detailed Academic Explanation:
filestream is the correct answer to “Which of the following is not a file stream class in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the function used to write data to a file in C++?
Correct Answer: Option C — file << data
Detailed Academic Explanation:
file << data is the correct answer to “What is the function used to write data to a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to set the file position in C++ file handling?
Correct Answer: Option B — seekg()
Detailed Academic Explanation:
seekg() is the correct answer to “Which function is used to set the file position in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the ios::ate flag in C++ file handling?
Correct Answer: Option B — Sets the get position pointer at the end of the file
Detailed Academic Explanation:
Sets the get position pointer at the end of the file is the correct answer to “What is the purpose of the ios::ate flag in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C++, how do you check if a file has reached the end while reading?
Correct Answer: Option A — file.eof()
Detailed Academic Explanation:
file.eof() is the correct answer to “In C++, how do you check if a file has reached the end while reading”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to rewind the file pointer to the beginning of the file in C++?
Correct Answer: Option D — file.seekg(0)
Detailed Academic Explanation:
file.seekg(0) is the correct answer to “Which function is used to rewind the file pointer to the beginning of the file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the function used to read a single character from a file in C++?
Correct Answer: Option D — get()
Detailed Academic Explanation:
get() is the correct answer to “What is the function used to read a single character from a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a valid file mode in C++?
Correct Answer: Option A — w
Detailed Academic Explanation:
w is the correct answer to “Which of the following is not a valid file mode in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you delete a file in C++?
Correct Answer: Option C — removeFile()
Detailed Academic Explanation:
removeFile() is the correct answer to “How do you delete a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to return the current file pointer position in C++?
Correct Answer: Option B — tellg()
Detailed Academic Explanation:
tellg() is the correct answer to “Which function is used to return the current file pointer position in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to check if a file is open or not in C++?
Correct Answer: Option C — file.is_open()
Detailed Academic Explanation:
file.is_open() is the correct answer to “Which function is used to check if a file is open or not in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if you try to open a file that does not exist in C++ without specifying any flags?
Correct Answer: Option B — An error will occur
Detailed Academic Explanation:
An error will occur is the correct answer to “What happens if you try to open a file that does not exist in C++ without specifying any flags”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which file mode in C++ opens a file for reading and writing, and truncates it to zero length if it exists?
Correct Answer: Option C — wplus
Detailed Academic Explanation:
wplus is the correct answer to “Which file mode in C++ opens a file for reading and writing, and truncates it to zero length if it exists”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between fstream and ofstream in C++?
Correct Answer: Option A — fstream can read and write, ofstream can only write
Detailed Academic Explanation:
fstream can read and write, ofstream can only write is the correct answer to “What is the difference between fstream and ofstream in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file operation in C++ has encountered an error?
Correct Answer: Option C — file.fail()
Detailed Academic Explanation:
file.fail() is the correct answer to “How do you check if a file operation in C++ has encountered an error”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the ios::binary flag in C++ file handling?
Correct Answer: Option A — Opens the file in binary mode
Detailed Academic Explanation:
Opens the file in binary mode is the correct answer to “What is the purpose of the ios::binary flag in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to close a file in C++?
Correct Answer: Option D — file.close()
Detailed Academic Explanation:
file.close() is the correct answer to “Which of the following is used to close a file in C++”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C++, how do you check if a file operation has reached the end of the file?
Correct Answer: Option A — file.eof()
Detailed Academic Explanation:
file.eof() is the correct answer to “In C++, how do you check if a file operation has reached the end of the file”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to set the position of the file pointer in C++ file handling?
Correct Answer: Option B — seekp()
Detailed Academic Explanation:
seekp() is the correct answer to “Which function is used to set the position of the file pointer in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if a file exists in C++ before opening it?
Correct Answer: Option A — file.exists()
Detailed Academic Explanation:
file.exists() is the correct answer to “How do you check if a file exists in C++ before opening it”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the ios::trunc flag in C++ file handling?
Correct Answer: Option A — Truncates the file if it exists and opens it in write mode
Detailed Academic Explanation:
Truncates the file if it exists and opens it in write mode is the correct answer to “What is the purpose of the ios::trunc flag in C++ file handling”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which file mode in C++ opens a file for reading and writing without truncating it if it exists?
Correct Answer: Option D — readplus
Detailed Academic Explanation:
readplus is the correct answer to “Which file mode in C++ opens a file for reading and writing without truncating it if it exists”. This question is standard in competitive examination syllabi for File Handling In C Plus Plus.
💡Key Conceptual Anchor:File Handling In C Plus Plus
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.