测试流中的错误。Tests for an error on a stream.


int ferror(   
   FILE *stream   


指向 FILE 结构的指针。Pointer to FILE structure.

返回值Return Value

如果 stream 中未发生错误,则 ferror 将返回 0。If no error has occurred on stream, ferror returns 0. 否则,返回一个非零值。Otherwise, it returns a nonzero value. 如果流为 NULLferror 将调用无效参数处理程序,如参数验证中所述。If stream is NULL, ferror invokes the invalid parameter handler, as described in Parameter Validation. 如果允许执行继续,则该函数将 errno 设置为 EINVAL 并返回 0。If execution is allowed to continue, this function sets errno to EINVAL and returns 0.

有关这些代码以及其他错误代码的详细信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerrSee _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, error codes.


ferror 例程(同时作为函数和宏实现)测试与 stream 相关联的文件的读取或写入错误。The ferror routine (implemented both as a function and as a macro) tests for a reading or writing error on the file associated with stream. 如果发生错误,则流的错误指示符将保留设置,直到关闭或回退流,或直到针对流调用 clearerrIf an error has occurred, the error indicator for the stream remains set until the stream is closed or rewound, or until clearerr is called against it.


函数Function 必需的标头Required header
ferror <stdio.h><stdio.h>

有关其他兼容性信息,请参见“简介”中的 兼容性For additional compatibility information, see Compatibility in the Introduction.


请参阅 feof 的示例。See the example for feof.

请参阅See Also

错误处理 Error Handling
流 I/O Stream I/O
clearerr clearerr
_eof _eof
feof feof
fopen、_wfopen fopen, _wfopen
perror、_wperrorperror, _wperror