C++ File Handling
Quiz on C++ file handling including file streams, open modes, file pointer operations, and file I/O functions
Questions
Which of the following is the disadvantage of binary data files?
- They can be easily read and written.
- They need a special program to read and write.
- Processing of binary files is slow.
- Binary data files are damaged easily.
To open the file for reading purpose, we have to create an object of ____________ class.
- iostream
- ofstream
- ifstream
- iofstream
Which of the following member functions is used to get a single character from a file?
- get()
- getc()
- cin
- put()
Which of the options shows the correct steps to process a file in C++ program?
- Name the file, open the file and close the file
- Open the existing file, read/write the file and close the file
- Open the file, read the file and write a file
- Create a file, open the file and close the file
Which of the following functions give the current position of the file pointer?
- tellme() and giveme()
- tellp() and tellg()
- put() and get()
- seekp() and seekg()
Which of the following is the invalid open mode of a file in C++?
- In
- out
- app
- ale
Normally a file is opened with positioning the cursor at the beginning of the file. But which mode opens the file by positioning the cursor at the end of file?
- ate
- app
- end
- aen
Which statement takes the file pointer to the beginning of the file?
- filepointer.seekg(0L,ios::start);
- filepointer.seekg(1L,ios::beg);
- filepointer.seekg(0L,ios::beg);
- filepointer.seekg(0L,io::beg);
Which of the following file opening modes shows error, if the file does not already exist?
- ios::in
- ios::out
- ios::noreplace
- ios::nocreate
____________ is used when we want to access the streams of bytes from memory.
- istream class
- ostream class
- strstream class
- istrstream class
How to check whether a file stream f1 was successfully opened or not?
- if(f1.open()) { .......... }
- if(f1.isopen) { ........... }
- if(f1.is_open()) { ............. }
- If(f1.is_open) { ................ }
Which method can be used to check the status after read/write operation?
- good()
- rdstate()
- clear()
- isstate()
Which of the following is not used for reading a text file?
- get(ch) function
- geline() function
- extraction operator
- open() function
Which of the following is the default mode for a open() member function of fstream class?
- ios::in
- ios::out
- ios::app
- ios::in | ios::out