File Handling in C++ – MCQs July 22, 2025 by u930973931_answers 30 Score: 0 Attempted: 0/30 Subscribe 1. : What header file is used for file handling in C++? 2. : Which class is used to write to a file in C++? (A) ifstream (B) ofstream (C) fstream (D) filewriter 3. : Which class is used to read from a file in C++? (A) ifstream (B) ofstream (C) fstream (D) fileReader 4. : Which class allows both reading and writing to a file in C++? (A) ifstream (B) fstream (C) ofstream (D) iostream 5. : What function is used to open a file? (A) start() (B) open() (C) load() (D) begin() 6. : Which function checks whether a file is open? (A) check() (B) fileopen() (C) is_open() (D) open_status() 7. : Which mode opens a file for reading only? (A) ios::out (B) ios::in (C) ios::app (D) ios::ate 8. : Which mode opens a file for appending data at the end? (A) ios::out (B) ios::in (C) ios::app (D) ios::trunc 9. : Which mode truncates the file to zero length if it exists? (A) ios::in (B) ios::out (C) ios::trunc (D) ios::binary 10. : Which mode is used for binary file operations? (A) ios::in (B) ios::out (C) ios::binary (D) ios::app 11. : What is the default mode for ofstream? (A) ios::in (B) ios::out (C) ios::app (D) ios::binary 12. : What happens if a file cannot be opened? (A) The program terminates (B) A new file is created (C) is_open() returns false (D) Data is lost 13. : What function is used to write to a file? (A) read() (B) input() (C) write() (D) << 14. : What function is used to read from a file? 15. : What is the purpose of eof() function? (A) To open a file (B) To detect end of file (C) To format the file (D) To save the file 16. : What is the full form of EOF? (A) End of Field (B) Error of File (C) End of File (D) End of Format 17. : What does getline() do? (A) Reads the entire file (B) Reads a line of text from the file (C) Writes a line to the file (D) Gets a character from the file 18. : Which function closes a file? (A) exit() (B) close() (C) end() (D) stop() 19. : Which stream is used for both input and output? (A) ifstream (B) ofstream (C) iostream (D) fstream 20. : What happens if you try to read from a file that does not exist? (A) File is created (B) Error occurs (C) Blank output (D) File is renamed 21. : What happens if you write to a file opened in ios::in mode? (A) Success (B) Compile error (C) Runtime error (D) Nothing happens 22. : Which operator is overloaded in C++ for file I/O? (A) == (B) >> and << (C) + (D) -> 23. : Which data type is used for file pointers in C++? (A) char* (B) ifstream (C) fstream (D) file* 24. : What is the purpose of seekg()? (A) Sets output position (B) Reads data (C) Moves the get pointer (D) Deletes data 25. : What does tellg() return? (A) File size (B) Write position (C) Read position (D) File name 26. : What is the default file mode for ifstream? (A) ios::out (B) ios::in (C) ios::app (D) ios::trunc 27. : What happens when ofstream opens a file that already exists? (A) Appends to file (B) Deletes and creates a new file (C) Renames the file (D) Throws error 28. : Which function is used to skip whitespaces while reading? (A) getline() (B) skipws (C) noskipws (D) clear() 29. : Which file mode ensures the file is not deleted when opened? (A) ios::out (B) ios::trunc (C) ios::app (D) ios::ate 30. : Which C++ stream handles errors related to file I/O? (A) cerr (B) cout (C) clog (D) cin