C++ Programming Multiple Choice Questions - File Handling

This section focuses on the "File Handling" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which stream class is to only write on files ?

A. ofstream
B. ifstream
C. fstream
D. iostream

View Answer


2. It is not possible to combine two or more file opening mode in open () method.

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


3. Which of these is the correct statement about eof() ?

A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.

View Answer


4. Which of the following true about FILE *fp

A. FILE is a structure and fp is a pointer to the structure of FILE type
B. FILE is a buffered stream
C. FILE is a keyword in C for representing files and fp is a variable of FILE type
D. FILE is a stream

View Answer


5. Which of the following methods can be used to open a file in file handling?

A. Using Open ( )
B. Constructor method
C. Destructor method
D. Both A and B

View Answer


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

A. >>
B. <<
C. <
D. None of the above

View Answer


7. 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);

View Answer


8. What is the output of this program?

         
Note:Includes all required header files
using namespace std;
    int main () 
    {
        int l;
        char * b;
        ifstream i;
        i.open ("find.txt", ios :: binary );
        i.seekg (0, ios :: end);
        l = i.tellg();
        i.seekg (0, ios :: beg);
        b = new char [l];
        i.read (b, l);
        i.close();
        cout.write (b, l);
        delete[] b;
        return 0;
    }
	

A. Error
B. find
C. This is find
D. Runtime error

View Answer


9. What is the output of this program?

         
Note:Includes all required header files
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

View Answer


10. 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

View Answer





Also check :


Discussion


* You must be logged in to add comment.