hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Which of the following statements is/are correct? 1. It is not possible to combine two or more file opening modes in the open() method. 2. It is
    Question



    Which of the following statements is/are correct?
    1. It is not possible to combine two or more file opening modes in the open() method.
    2. It is possible to combine two or more file opening modes in the open() method.
    3. ios::in and ios::out are input and output file opening modes, respectively.

    A.

    1, 3

    B.

    2, 3

    C.

    3 only

    D.

    More than one of the above

    E.

    None of the above

    Correct option is A

    Statement 1: "It is not possible to combine two or more file opening modes in open() method." Correct
    · In C++, the open() method does not allow multiple file opening modes to be combined directly.
    · The open() method can only be used to open one file at a time.
    · However, multiple flags (modes) can be combined using bitwise OR (|), but not multiple files in one call.
    Statement 2: "It is possible to combine two or more file opening modes in open() method." Incorrect
    · This statement is incorrect because the open() method cannot open multiple files at once.
    · It can, however, combine multiple modes (ios::in | ios::out).
    Statement 3: "ios::in and ios::out are input and output file opening modes, respectively." Correct
    · ios::in → Opens a file in input (read) mode.
    · ios::out → Opens a file in output (write) mode.
    · These modes are used with ifstream, ofstream, and fstream.
    Example of File Opening Modes in C++:
    #include <fstream>
    using namespace std;
    int main() {
    fstream file;
    file.open("example.txt", ios::in | ios::out | ios::app); // Combining file modes
    return 0;
    }
    · Here, ios::in | ios::out | ios::app combines multiple modes, but only for one file at a time.
    Knowledge Booster:
    · ios::binary is used for opening files in binary mode.
    · ios::trunc is used to delete file content when opening in output mode.
    · Use fstream when you need both read and write operations.

    Free Tests

    Free
    Must Attempt

    UPTET : Paper 1 Full Mock - 01

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 Mins
    languageIcon English
    Free
    Must Attempt

    UPTET : Paper 2 Maths & Science Full Mock - 01

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 Mins
    languageIcon English
    Free
    Must Attempt

    UPTET : Paper 2 Social Science Full Mock - 01

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 Mins
    languageIcon English
    test-prime-package

    Access ‘BPSC TRE (11-12)’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    416k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow