首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ferror

Defined in header <cstdio>

?

?

int ferror( std::FILE* stream );

?

?

检查给定流是否有错误。

参数

stream

-

the file stream to check

返回值

如果文件流发生错误,则为非零值,?0?否则。

二次

代码语言:javascript
复制
#include <cstdio>
#include <cstdlib>
#include <clocale>
#include <cwchar>
 
int main(void)
{
    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");
}

二次

产出:

二次

代码语言:javascript
复制
Error indicator set

二次

另见

clearerr

clears errors (function)

feof

checks for the end-of-file (function)

fail

checks if an error has occurred (public member function of std::basic_ios)

C错误文档

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com