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