Share via


clearerr_s

重置流的错误指示器。 这是 clearerr 的版本与安全增强的 CRT中的安全功能如中所述。

errno_t clearerr_s(
   FILE *stream 
);

参数

  • stream
    为 FILE 结构的指针

返回值

零,如果成功; EINVAL ,如果 stream 为空。

备注

clearerr_s 功能重置错误指示器和文件尾指示符的 stream。 不会自动清除错误指示器;一个指定的流的错误指示器设置,在该流的操作继续返回直到 clearerr_s, clearerr, fseek, fsetpos的错误值,或 rewind 调用。

如果 stream 为空,则无效参数调用处理程序,如 参数验证所述。 如果执行允许继续,此功能设置 errno 到 EINVAL 并返回 EINVAL。

要求

实例

必需的头

clearerr_s

stdio.h

有关其他的兼容性信息,请参见中介绍的 兼容性

示例

// crt_clearerr_s.c
// This program creates an error
// on the standard input stream, then clears
// it so that future reads won't fail.
 

#include <stdio.h>

int main( void )
{
   int c;
   errno_t err;

   // Create an error by writing to standard input.
   putc( 'c', stdin );
   if( ferror( stdin ) )
   {
      perror( "Write error" );
      err = clearerr_s( stdin );
      if (err != 0)
      {
         abort();
      }
   }

   // See if read causes an error.
   printf( "Will input cause an error? " );
   c = getc( stdin );
   if( ferror( stdin ) )
   {
      perror( "Read error" );
      err = clearerr_s( stdin );
      if (err != 0)
      {
         abort();
      }
   }
}
  nnWrite

FakePre-c34ef202e56046eda238eef66c4d1c4f-81d43fe3678c4e7cb284eef5997fb0b4

.NET Framework 等效项

不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见 平台调用示例

请参见

参考

错误处理(crt)

流I/O

clearerr

_eof

feof

ferror

perror, _wperror