The stream I/O system does not return an error status flag directly, but rather it yields a value that can be converted into a boolean value that indicates the error:
The stream I/O system does not return an error status flag directly, but rather it yields a value that can be converted into a boolean value that indicates the error:
istream fin("filename.dat"); // open fileif (! fin) { // convert to boolean and test // ... handle error case}
FILE *fp = fopen("rahrah.dat", "w"); // open filefputc('O', fp); // write a few charactersfputc('S', fp);fputc('U', fp);if (ferror(fp)) // did an error occur in any of the previous? ... // handle error case