名稱空間
變體
操作

std::ferror

來自 cppreference.com
< cpp‎ | io‎ | c
 
 
 
 
定義於標頭檔案 <cstdio>
int ferror( std::FILE* stream );

檢查給定流的錯誤。

目錄

[編輯] 引數

stream - 要檢查的檔案流

[編輯] 返回值

如果檔案流發生錯誤,返回非零值;否則返回 0

[編輯] 示例

#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
 
int main()
{
    const char *fname = std::tmpnam(nullptr);
    std::FILE* f = std::fopen(fname, "wb");
    std::fputs("\xff\xff\n", f); // not a valid UTF-8 character sequence
    std::fclose(f);
 
    std::setlocale(LC_ALL, "en_US.utf8");
    f = std::fopen(fname, "rb");
    std::wint_t ch;
    while ((ch=std::fgetwc(f)) != WEOF) // attempt to read as UTF-8
        std::printf("%#x ", ch);
 
    if (std::feof(f))
        puts("EOF indicator set");
    if (std::ferror(f))
        puts("Error indicator set");
}

輸出

Error indicator set

[編輯] 參閱

清除錯誤
(函式) [編輯]
檢查檔案結束
(函式) [編輯]
檢查是否發生錯誤
(std::basic_ios<CharT,Traits> 的公共成員函式) [編輯]
C 文件 用於 ferror