Multiple choice

Select the proper object type in C++. __________ file (“file. dat”, ios::in | ios::out)

  1. iostream

  2. fstream

  3. ofstream

  4. ifstream

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

fstream is the correct C++ class for file operations that require both input and output capabilities. The ios::in | ios::out flags indicate we need to both read from and write to the file, which fstream supports. iostream only handles console I/O, while ifstream and ofstream are specialized for input-only or output-only operations respectively.