Which statement opens a file for binary output?

Options

  • A. ofstream fout("data.bin", ios::in);
  • B. ifstream fin("data.bin", ios::out);
  • C. ofstream fout("data.bin", ios::out | ios::binary);
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. ofstream fout("data.bin", ios::out | ios::binary);

Detailed Explanation

Correct Answer: Option C

Explanation:
ios::out requests output access and ios::binary requests binary mode. When used with an ofstream, the output mode normally truncates an existing file unless an appropriate alternative mode is specified.