在线文档教程
C++
输入/输出 | Input/output

std::ferror

STD:错误

Defined in header
int ferror( std::FILE* stream

检查给定流是否有错误。

参数

stream-the file stream to check

返回值

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

二次

#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" }

二次

产出:

二次

Error indicator set

二次

另见

clearerrclears errors (function)
feofchecks for the end-of-file (function)
failchecks if an error has occurred (public member function of std::basic_ios)

C错误文档

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/c/fror