C++ File Handling Questions Answers

  • 1. 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);
    Answer :

    Option B

  • 2. Which among following is used to open a file in binary mode ?

    1. ios:app
    2. ios::out
    3. ios::in
    4. ios::binary
    Answer :

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

  • 3. How to find the position at end of fileObject ?

    1. fileObject.seekg( 0, ios::end );
    2. fileObject.seekg( 0, ios::end );
    3. fileObject.seekg( 0, ios::end );
    4. fileObject.seekg( 0, ios::end );
    Answer :

    Option A

  • 4. Which stream class is to only read from files ?

    1. ofstream
    2. ifstream
    3. fstream
    4. iostream
    Answer :

    Option B

  • 5. Which among following is correct syntax of closing a file in c++ ?

    1. myfile$close();
    2. [email protected]();
    3. myfile:close();
    4. myfile.close();
    Answer :

    Option D

  • 6. Which stream class is used to both read and write on files ?

    1. ofstream
    2. ifstream
    3. fstream
    4. iostream
    Answer :

    Option C

  • 7. How to get position n bytes forward in fileObject ?

    1. fileObject.seekg( ios::cur, n );
    2. fileObject.seekg( n, ios:cur );
    3. fileObject.seekg( n, ios::cur );
    4. fileObject.seekg( ios:cur, n );
    Answer :

    Option C

Please Like Us

disawar satta king