std::clearerr
From cppreference.com
| ヘッダ <cstdio>で定義 |
||
| void clearerr( std::FILE* stream ); |
||
指定されたファイルストリームのエラーフラグとEOFインジケータをリセットします。
目次 |
[編集] パラメータ
| stream | - | エラーフラグをリセットするファイル |
[編集] 戻り値
(なし)
[編集] 例
このコードを実行
#include <cassert> #include <cstdio> int main() { std::FILE* tmpf = std::tmpfile(); std::fputs("cppreference.com\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.com End of file reached EOF indicator cleared
[編集] 関連項目
| ファイルの終端をチェックする (関数) | |
| 現在のエラーに対応する文字列を stderr に表示する (関数) | |
| ファイルエラーをチェックする (関数) | |
| C ドキュメント の clearerr
| |