C++ File Handling Questions Answers
-
1. Which is correct syntax ?
- myfile:open ("example.bin", ios::out);
- myfile.open ("example.bin", ios::out);
- myfile::open ("example.bin", ios::out);
- myfile.open ("example.bin", ios:out);
Answer :
Option B
-
2. Which among following is used to open a file in binary mode ?
- ios:app
- ios::out
- ios::in
- ios::binary
Answer :
Option D
Explanation:
ios:app -> All output operations are performed at the end of the file, appending the content to the current content of the file.
ios::out -> Open for output operations.
ios::in -> Open for input operations. -
3. How to find the position at end of fileObject ?
- fileObject.seekg( 0, ios::end );
- fileObject.seekg( 0, ios::end );
- fileObject.seekg( 0, ios::end );
- fileObject.seekg( 0, ios::end );
Answer :
Option A
-
4. Which stream class is to only read from files ?
- ofstream
- ifstream
- fstream
- iostream
Answer :
Option B
-
5. Which among following is correct syntax of closing a file in c++ ?
- myfile$close();
- [email protected]();
- myfile:close();
- myfile.close();
Answer :
Option D
-
6. Which stream class is used to both read and write on files ?
- ofstream
- ifstream
- fstream
- iostream
Answer :
Option C
-
7. How to get position n bytes forward in fileObject ?
- fileObject.seekg( ios::cur, n );
- fileObject.seekg( n, ios:cur );
- fileObject.seekg( n, ios::cur );
- fileObject.seekg( ios:cur, n );
Answer :
Option C