Go to IBPS EXPERT

C++ File Handling Questions Answers

C++ File Handling Questions Answers includes important questions on File Handling in C++ Programming Language which are important for IBPS IT Officer Aptitude exam, Campus Placements and other technical interviews and exams.

1) Which stream class is to only write on files

  • 1) ofstream
  • 2) ifstream
  • 3) fstream
  • 4) iostream
View Answer View Explanation
Ans.   A
Explanation :

2) Which stream class is to only read from files

  • 1) ofstream
  • 2) ifstream
  • 3) fstream
  • 4) iostream
View Answer View Explanation
Ans.   B
Explanation :

3) Which stream class is used to both read and write on files

  • 1) ofstream
  • 2) ifstream
  • 3) fstream
  • 4) iostream
View Answer View Explanation
Ans.   C
Explanation :

4) Which among following is used to open a file in binary mode

  • 1) ios:app
  • 2) ios::out
  • 3) ios::in
  • 4) ios::binary
View Answer View Explanation
Ans.   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.

5) ios::trunc is used for

  • 1) If the file is opened for output operations and it already existed, no action is taken.
  • 2) If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
  • 3) If the file is opened for output operations and it already existed, then a new copy is created.
  • 4) None of above
View Answer View Explanation
Ans.   B
Explanation :

6) Which is correct syntax

  • 1) myfile:open ('example.bin', ios::out);
  • 2) myfile.open ('example.bin', ios::out);
  • 3) myfile::open ('example.bin', ios::out);
  • 4) myfile.open ('example.bin', ios:out);
View Answer View Explanation
Ans.   B
Explanation :

7) Which among following is correct syntax of closing a file in c++

  • 1) myfile$close();
  • 2) myfile@close();
  • 3) myfile:close();
  • 4) myfile.close();
View Answer View Explanation
Ans.   D
Explanation :

8) What is use of eof()

  • 1) Returns true if a file open for reading has reached the next character.
  • 2) Returns true if a file open for reading has reached the next word.
  • 3) Returns true if a file open for reading has reached the end.
  • 4) Returns true if a file open for reading has reached the middle.
View Answer View Explanation
Ans.   C
Explanation :

9) Which functions allow to change the location of the get and put positions

  • 1) sg() and sp()
  • 2) sekg() and sekp()
  • 3) gog() and gop()
  • 4) seekg() and seekp()
View Answer View Explanation
Ans.   D
Explanation :

10) offset counted from the current position usin

  • 1) ios::curr
  • 2) ios::cr
  • 3) ios::cur
  • 4) ios::current
View Answer View Explanation
Ans.   C
Explanation :
Get Free Current Affairs and Govt Jobs Alerts in your mailbox
Current Affairs
Govt Jobs

Testing