Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ File Management MCQ | Set 3

C++ File Management | Set 3


21. Which operator is used to insert the data into file?

a) >>
b) <<
c) <
d) None of the above



22. Which is correct syntax?

a) myfile:open ("example.bin", ios::out);
b) myfile.open ("example.bin", ios::out);
c) myfile::open ("example.bin", ios::out);
d) myfile.open ("example.bin", ios:out);



23. ios::trunc is used for ?

a) If the file is opened for output operations and it already existed, no action is taken.
b) If the file is opened for output operations and it already existed, then a new copy is created.
c) If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
d) None of the above



24. In fopen(), the open mode "wx" is sometimes preferred "w" because. i) Use of wx is more efficient. ii) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.

a) Only i
b) Only ii
c) Both i & ii
d) None of the above



25. Which member function is used to determine whether the stream object is currently associated with a file?

a) is_open
b) Buf
c) String
d) None of the above



26. getc() returns EOF when

a) End of files is reached
b) When getc() fails to read a character
c) Both A & B
d) None of the above



27. Which of the following is not a file opening mode ____ .

a) ios::ate
b) ios::nocreate
c) ios::noreplace
d) ios::truncate



28. Due to ios::trunc mode, the file is truncated to zero length.

a) True
b) False



29. If we have object from fstream class, then what is the default mode of opening the file?

a) ios::in|ios::out
b) ios::in|ios::out|ios::trunc
c) ios::in|ios::trunc
d) Default mode depends on compiler



30. What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main() {

    char fine, course;
    cout << "Enter a word: ";
    fine = cin.get();
    cin.sync();
    
    course = cin.get();
    cout << fine << endl;
    cout << course << endl;
    
    return 0;
}

a) course
b) fine
c) Returns fine 2 letter or number from the entered word
d) None of the mentioned



- Related Topics