Which of the following C++ statements will open a text file "VIEWS.TXT" in…

2022

Which of the following C++ statements will open a text file "VIEWS.TXT" in which read as well as write activities are required at the same time?

  1. A.

    fstream F("VIEWS.TXT", ios::read | ios::write);

  2. B.

    fstream F("VIEWS.TXT", ios::in | ios::out);

  3. C.

    fstream F("VIEWS.TXT", ios::in ? ios::out);

  4. D.

    fstream F("VIEWS.TXT", ios::read ? write);

Attempted by 176 students.

Show answer & explanation

Correct answer: B

In C++, the fstream class is used for both reading and writing files. To enable reading and writing simultaneously, open the file using ios::in

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs