clearerr
From cppreference.net
File input/output
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<stdio.h>
|
||
|
void
clearerr
(
FILE
*
stream
)
;
|
||
指定されたファイルストリームのエラーフラグと
EOF
インジケータをリセットします。
目次 |
パラメータ
| stream | - | エラーフラグをリセットする対象のファイル |
戻り値
(なし)
例
このコードを実行
#include <stdio.h> #include <assert.h> int main(void) { FILE* tmpf = tmpfile(); fputs("cppreference.net\n", tmpf); rewind(tmpf); for (int ch; (ch = fgetc(tmpf)) != EOF; putchar(ch)) { } assert(feof(tmpf)); // ループはEOFで終了することが期待される puts("End of file reached"); clearerr(tmpf); // EOFをクリア puts(feof(tmpf) ? "EOF indicator set" : "EOF indicator cleared"); }
出力:
cppreference.net End of file reached EOF indicator cleared
参考文献
- C17規格 (ISO/IEC 9899:2018):
-
- 7.21.10.1 clearerr関数 (p: 246)
- C11規格 (ISO/IEC 9899:2011):
-
- 7.21.10.1 clearerr関数 (p: 338)
- C99規格 (ISO/IEC 9899:1999):
-
- 7.19.10.1 clearerr関数 (p: 304)
- C89/C90標準 (ISO/IEC 9899:1990):
-
- 4.9.10.1 clearerr関数
関連項目
|
ファイル終端をチェックする
(関数) |
|
|
現在のエラーに対応する文字列を
stderr
に表示する
(関数) |
|
|
ファイルエラーをチェックする
(関数) |
|
|
C++ documentation
for
clearerr
|
|