名稱空間
變體
操作

clearerr

來自 cppreference.com
< c‎ | io
 
 
檔案輸入/輸出
型別和物件
        
函式
檔案訪問
(C95)
非格式化輸入/輸出
(C95)(C95)
(C95)
(C95)(C95)
(C95)
(C95)

格式化輸入
 
定義於標頭檔案 <stdio.h>
void clearerr( FILE *stream );

重置給定檔案流的錯誤標誌和 EOF 指示符。

目錄

[編輯] 引數

stream - 要重置錯誤標誌的檔案

[編輯] 返回值

(無)

[編輯] 示例

#include <stdio.h>
#include <assert.h>
 
int main(void)
{
    FILE* tmpf = tmpfile();
    fputs("cppreference.com\n", tmpf);
    rewind(tmpf);
 
    for (int ch; (ch = fgetc(tmpf)) != EOF; putchar(ch)) { }
 
    assert(feof(tmpf)); // the loop is expected to terminate by EOF
    puts("End of file reached");
 
    clearerr(tmpf); // clear EOF
 
    puts(feof(tmpf) ? "EOF indicator set" 
                    : "EOF indicator cleared");
}

輸出

cppreference.com
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++ 文件 for clearerr