std::ferror
提供: cppreference.com
ヘッダ <cstdio> で定義
|
||
int ferror( std::FILE* stream ); |
||
指定されたストリームのエラーを調べます。
目次 |
[編集] 引数
stream | - | 調べるファイルストリーム |
[編集] 戻り値
ファイルストリームにエラーが発生した場合は非ゼロの値、そうでなければ 0。
[編集] 例
Run this code
#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
[編集] 関連項目
エラーをクリアします (関数) | |
ファイルの終端かどうか調べます (関数) | |
エラーが発生したかどうか調べます ( std::basic_ios<CharT,Traits> のパブリックメンバ関数)
| |
ferror の C言語リファレンス
|