11.10 MISCELLANEOUS FUNCTIONS

The good, the bad and the ugly (fail)

A cowboy film “The good, the bad and the ugly” was very popular. A fan of Clint Eastwood must have been in the team, which designed the ios stream. That is why you have member functions named good(), bad() and fail(). As the names suggest they tell us about the I/O operations.

The function good() returns nonzero(true) if no error occurs during I/O operation. The function bad() returns nonzero(true) if error occurs during I/O operation. The function fail() returns nonzero(true) if error occurs during I/O operation.

It appears that good and bad should be complementary. However, it is not true. The return value is decided by checking certain flags. Let us study a simple program ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.