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