Skip to main content

File Handling

1).What is file handling in C++?

1) Managing files for reading and writing
2) Creating classes
3) Handling memory leaks
4) None of the above

2).Which header file is required for file handling?

1) <fstream>
2) <iostream>
3) <file.h>
4) None of the above

3).Which class is used for reading from files?

1) ifstream
2) ofstream
3) fstream
4) None of the above

4).Which class is used for writing to files?

1) ofstream
2) ifstream
3) fstream
4) None of the above

5).How do you open a file in append mode?

1) ios::app
2) ios::in
3) ios::out
4) None of the above

6).What is the default mode for opening a file?

1) ios::in
2) ios::out
3) ios::binary
4) None of the above

7).How do you check if a file was opened successfully?

1) Use the is_open() method
2) Check the file size
3) Read the file header
4) None of the above

8).What does the eof() function check?

1) End of file
2) File size
3) File permissions
4) None of the above

9).How do you close a file in C++?

1) Use the close() method
2) Use the end() method
3) Use the terminate() method
4) None of the above

10).What happens if you try to read from a file that doesn’t exist?

1) An error occurs
2) A new file is created
3) The program crashes
4) None of the above