名前空間
変種
操作

「cpp/io/basic ios/bad」の版間の差分

提供: cppreference.com
< cpp‎ | io‎ | basic ios
(Fix some translations)
 
1行: 1行:
{{tr_note}}
 
 
{{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}}
  
{{tr|戻り{{c|true}}回復不可能なエラーが関連付けられたストリームで発生した場合。具体的には、戻り{{c|true}}{{tt|badbit}}が{{c|rdstate()}}で設定されている場合.|Returns {{c|true}} if non-recoverable error has occurred on the associated stream. Specifically, returns {{c|true}} if {{tt|badbit}} is set in {{c|rdstate()}}.}}
+
{{c|true}} {{c|rdstate()}} {{||badbit}} {{c|}}
  
{{tr|標準ライブラリには、次のような状況でbadbitを設定します|The standard library sets badbit in the following situations:}}
+
{{|badbit}} {{|cpp/io//}}
* {{tr|(プット)やwrite()は、出力ストリームへの挿入は、何らかの理由で失敗した.|Insertion into the output stream by put() or write() fails for any reason.}}
+
* {{tr|[[cpp/io/basic_ostream/operator_ltlt|演算子<<]]によって出力ストリームへの挿入、または{{lc|std::put_money}}{{lc|std::put_time}}、出力ストリームの最後に(そのような{{ltt|cpp/locale/num_put/do_put|num_put::put()}}または{{ltt|cpp/locale/money_put/do_put|money_put::put()}}としてファセットのフォーマット出力機能、イテレータを返すよう{{tt|iter}}{{c|1=iter.failed()==true}}こと)に達したため完了できませんでした|Insertion into the output stream by [[cpp/io/basic_ostream/operator_ltlt|演算子<<]], {{lc|std::put_money}} or {{lc|std::put_time}}, could not complete because the end of the output stream was reached (The facet's formatting output function such as {{ltt|cpp/locale/num_put/do_put|num_put::put()}} or {{ltt|cpp/locale/money_put/do_put|money_put::put()}}, returns an iterator {{tt|iter}} such that {{c|1=iter.failed()==true}})}}
+
* {{tr|ストリームはRDBUFにNULLポインター()を使用して構築されている、またはプットバック()/ unget()はヌルRDBUF()、または演算子<<(basic_streambuf※)に渡されるNULLポインタをストリーム上で呼ばれています|Stream is constructed with a null pointer for rdbuf(), or putback()/unget() is called on a stream with a null rdbuf(), or a null pointer passed to operator<<(basic_streambuf*)}}
+
* {{tr|RDBUF() - > sputbackc()またはRDBUF() - > sungetc()の戻り形質:: eof()をプットバック()またはunget(へ)|rdbuf()->sputbackc() or rdbuf()->sungetc() return traits::eof() to putback() or unget()}}
+
* {{tr|フラッシュする> pubsync()が返す{{c|-1}}同期するように()、()、またはostreamのデストラクタへ:: unitbufストリーム上の歩哨 - RDBUF()|rdbuf()->pubsync() returns {{c|-1}} to sync(), to flush(), or to the destructor of ostream::sentry on a unitbuf stream}}
+
* {{tr|例外は、(、)sgetc(例えばsbumpc()、xsputn()オーバーフロー()など)は、関連するストリームバッファの任意のメンバ関数でI / O操作中にスローされます|Exception is thrown during an I/O operation by any member function of the associated stream buffer (e.g. sbumpc(), xsputn(), sgetc(), overflow(), etc)}}
+
* {{tr|例外はiword()やpword()(例えばstd :: bad_allocだけ)にスローされます|Exception is thrown in iword() or pword() (e.g. std::bad_alloc)}}
+
  
===パラメータ===
+
======
 
(なし)
 
(なし)
  
===値を返します===
+
======
{{tr|{{c|true}}回復不能なエラーが発生した場合、{{c|false}}その他のとき.|{{c|true}} if a non-recoverable error has occurred, {{c|false}} otherwise.}}
+
{{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時点における最新版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
bool bad() const;

紐付けられているストリームに回復不可能なエラーが発生していれば true を返します。 具体的には、 rdstate()badbit がセットされていれば true を返します。

badbit がセットされる状況の一覧は ios_base::iostate を参照してください。

目次

[編集] 引数

(なし)

[編集] 戻り値

回復不可能なエラーが発生していれば true、そうでなければ false

[編集]

#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() など) の値を示します。