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?
- A.
fstream F("VIEWS.TXT", ios::read | ios::write);
- B.
fstream F("VIEWS.TXT", ios::in | ios::out);
- C.
fstream F("VIEWS.TXT", ios::in ? ios::out);
- 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