「cpp/io/basic ios/bad」の版間の差分
提供: cppreference.com
細 (Fix some translations) |
|||
1行: | 1行: | ||
− | |||
{{cpp/io/basic_ios/title | bad}} | {{cpp/io/basic_ios/title | bad}} | ||
{{cpp/io/basic_ios/navbar}} | {{cpp/io/basic_ios/navbar}} | ||
8行: | 7行: | ||
{{dcl end}} | {{dcl end}} | ||
− | + | {{c|true}} {{c|rdstate()}} {{||badbit}} {{c|}} | |
− | {{ | + | {{|badbit}} {{|cpp/io//}} |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === | + | ====== |
(なし) | (なし) | ||
− | === | + | ====== |
− | + | {{c|true}}{{c|false}} | |
===例=== | ===例=== | ||
{{example template|cpp/io/basic_ios/example1}} | {{example template|cpp/io/basic_ios/example1}} | ||
− | === | + | ====== |
{{cpp/io/basic ios/iostate accessors}} | {{cpp/io/basic ios/iostate accessors}} | ||
2018年6月2日 (土) 17:32時点における最新版
bool bad() const; |
||
紐付けられているストリームに回復不可能なエラーが発生していれば true を返します。 具体的には、 rdstate() の badbit がセットされていれば true を返します。
badbit
がセットされる状況の一覧は ios_base::iostate を参照してください。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
回復不可能なエラーが発生していれば true、そうでなければ false。
[編集] 例
Run this code
#include <iostream> #include <fstream> #include <cstdlib> int main() { std::ifstream file("test.txt"); if(!file) // operator! is used here { std::cout << "File opening failed\n"; return EXIT_FAILURE; } // typical C++ I/O loop uses the return value of the I/O function // as the loop controlling condition, operator bool() is used here for(int n; file >> n; ) { std::cout << n << ' '; } std::cout << '\n'; if (file.bad()) std::cout << "I/O error while reading\n"; else if (file.eof()) std::cout << "End of file reached successfully\n"; else if (file.fail()) std::cout << "Non-integer data encountered\n"; }
[編集] 関連項目
以下の表は ios_base::iostate フラグのすべての有り得る組み合わせに対する basic_ios
のアクセサ (good()、 fail() など) の値を示します。