C++ File Handling

Quiz on C++ file handling including file streams, open modes, file pointer operations, and file I/O functions

14 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following is the disadvantage of binary data files?

  1. They can be easily read and written.
  2. They need a special program to read and write.
  3. Processing of binary files is slow.
  4. Binary data files are damaged easily.
Question 2 Multiple Choice (Single Answer)

To open the file for reading purpose, we have to create an object of ____________ class.

  1. iostream
  2. ofstream
  3. ifstream
  4. iofstream
Question 3 Multiple Choice (Single Answer)

Which of the following member functions is used to get a single character from a file?

  1. get()
  2. getc()
  3. cin
  4. put()
Question 4 Multiple Choice (Single Answer)

Which of the options shows the correct steps to process a file in C++ program?

  1. Name the file, open the file and close the file
  2. Open the existing file, read/write the file and close the file
  3. Open the file, read the file and write a file
  4. Create a file, open the file and close the file
Question 5 Multiple Choice (Single Answer)

Which of the following functions give the current position of the file pointer?

  1. tellme() and giveme()
  2. tellp() and tellg()
  3. put() and get()
  4. seekp() and seekg()
Question 6 Multiple Choice (Single Answer)

Which of the following is the invalid open mode of a file in C++?

  1. In
  2. out
  3. app
  4. ale
Question 7 Multiple Choice (Single Answer)

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?

  1. ate 
  2. app 
  3. end 
  4. aen 
Question 8 Multiple Choice (Single Answer)

Which statement takes the file pointer to the beginning of the file?

  1. filepointer.seekg(0L,ios::start);
  2. filepointer.seekg(1L,ios::beg);
  3. filepointer.seekg(0L,ios::beg);
  4. filepointer.seekg(0L,io::beg);
Question 9 Multiple Choice (Single Answer)

Which of the following file opening modes shows error, if the file does not already exist?

  1. ios::in
  2. ios::out
  3. ios::noreplace
  4. ios::nocreate
Question 10 Multiple Choice (Single Answer)

____________ is used when we want to access the streams of bytes from memory.

  1. istream class
  2. ostream class
  3. strstream class
  4. istrstream class
Question 11 Multiple Choice (Single Answer)

How to check whether a file stream f1 was successfully opened or not?

  1. if(f1.open()) { .......... }
  2. if(f1.isopen) { ........... }
  3. if(f1.is_open()) { ............. }
  4. If(f1.is_open) { ................ }
Question 12 Multiple Choice (Single Answer)

Which method can be used to check the status after read/write operation?

  1. good()
  2. rdstate()
  3. clear()
  4. isstate()
Question 13 Multiple Choice (Single Answer)

Which of the following is not used for reading a text file?

  1. get(ch) function
  2. geline() function
  3. extraction operator
  4. open() function
Question 14 Multiple Choice (Single Answer)

Which of the following is the default mode for a open() member function of fstream class?

  1. ios::in
  2. ios::out
  3. ios::app
  4. ios::in | ios::out