Which access is requested by the following C++ statement?

fstream file("data.txt", ios::in | ios::out);
                        

Options

  • A. Input only
  • B. Output only
  • C. Both input and output
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Both input and output

Detailed Explanation

Correct Answer: Option C

Explanation:
ios::in requests input access, while ios::out requests output access. Combining them with | requests both. If the file does not already exist, opening it this way generally fails.