std::ferror
From cppreference.com
| ヘッダ <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> の public メンバ関数) | |
| C言語のドキュメント (ferror)
| |