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

2023

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

  4. D.

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

Attempted by 131 students.

Show answer & explanation

Correct answer: B

In C++, the fstream class is used for both input and output operations. ios::in opens the file for reading.

ios::out opens the file for writing.

Using them together ( ios::in

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs