ferror() - I/O Function
How is ferror() used in C++?
How to check file error?
Explanation
ferror() is an I/O function which is used to check if there is any file error in the given stream. If the value returned is "0" indicates of no error. A value other than "0" indicates that an file error has occurred.
Syntax:
int ferror ( FILE * stream );
Example :
#include <stdio.h> int main() { FILE * stri = fopen ("getceg.txt", "r"); if( ferror(stri)==0 ) { perror ("No file error"); } else { perror( "File error encountered" ); } return 0; } |
Result :
No file error: Error 0
In the above example the function is used to check if there is any error while accessing the file "getceg.txt", it returns the result.