std::clearerr
来自 cppreference.cn
定义于头文件 <cstdio> |
||
void clearerr( std::FILE* stream ); |
||
重置给定文件流的错误标志和 EOF
指示器。
内容 |
[edit] 参数
stream | - | 要重置错误标志的文件 |
[edit] 返回值
(无)
[edit] 示例
运行此代码
#include <cassert> #include <cstdio> int main() { std::FILE* tmpf = std::tmpfile(); std::fputs("cppreference.cn\n", tmpf); std::rewind(tmpf); for (int ch; (ch = std::fgetc(tmpf)) != EOF; std::putchar(ch)) { } assert(std::feof(tmpf)); // the loop is expected to terminate by EOF std::puts("End of file reached"); std::clearerr(tmpf); // clear EOF std::puts(std::feof(tmpf) ? "EOF indicator set" : "EOF indicator cleared"); }
输出
cppreference.cn End of file reached EOF indicator cleared
[edit] 参见
检查文件结尾 (函数) | |
将对应于当前错误的字符串显示到 stderr (函数) | |
检查文件错误 (函数) | |
C 文档 关于 clearerr 的文档
|