Namespaces
Variants

std:: clearerr

From cppreference.net
< cpp ‎ | io ‎ | c
定义于头文件 <cstdio>
void clearerr ( std:: FILE * stream ) ;

重置指定文件流的错误标志和 EOF 指示器。

目录

参数

stream - 用于重置错误标志的文件

返回值

(无)

示例

#include <cassert>
#include <cstdio>
int main()
{
    std::FILE* tmpf = std::tmpfile();
    std::fputs("cppreference.net\n", tmpf);
    std::rewind(tmpf);
    for (int ch; (ch = std::fgetc(tmpf)) != EOF; std::putchar(ch)) { }
    assert(std::feof(tmpf)); // 预期循环通过EOF终止
    std::puts("End of file reached");
    std::clearerr(tmpf); // 清除EOF
    std::puts(std::feof(tmpf) ? "EOF indicator set"
                              : "EOF indicator cleared");
}

输出:

cppreference.net
End of file reached
EOF indicator cleared

参考

检查文件结尾
(函数)
将当前错误对应的字符串显示到 stderr
(函数)
检查文件错误
(函数)
C 文档 关于 clearerr