Multiple choice

Which one of the following error handling functions of ios class returns true, when an input or an output operation on file has failed?

  1. bad()

  2. good()

  3. eof()

  4. fail()

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

The fail() function returns true when a stream operation fails, including when an input/output operation on a file fails. This sets the failbit in the stream state. The bad() function is for serious errors like stream corruption, good() returns true if no errors occurred, and eof() checks for end-of-file condition specifically.