◐ Shell
clean mode source ↗

std::basic_ios::bad — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Retours true si erreur non récupérable s'est produite sur le flux associé. Plus précisément, les rendements true si badbit est situé dans rdstate() .

Original:

Returns true if non-recoverable error has occurred on the associated stream. Specifically, returns true if badbit is set in rdstate().

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

La bibliothèque standard définit BadBit dans les situations suivantes:

Original:

The standard library sets badbit in the following situations:

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

  • L'insertion dans le flux de sortie par put () ou write () échoue pour une raison quelconque .

    Original:

    Insertion into the output stream by put() or write() fails for any reason.

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • L'insertion dans le flux de sortie par << opérateur, std::put_money ou std::put_time, n'a pas pu terminer parce que la fin du flux de sortie a été atteint (fonction La facette de formatage de sortie tels que

    num_put::put()

    ou

    money_put::put()

    , retourne un itérateur iter tels que iter.failed()==true)

    Original:

    Insertion into the output stream by << opérateur, std::put_money or std::put_time, could not complete because the end of the output stream was reached (The facet's formatting output function such as

    num_put::put()

    or

    money_put::put()

    , returns an iterator iter such that iter.failed()==true)

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • Stream est construit avec un pointeur NULL pour rdbuf (), ou putback () / unget () est appelée sur un ruisseau avec un rdbuf nulle (), ou un pointeur NULL passé à l'opérateur << (* basic_streambuf)

    Original:

    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*)

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • rdbuf () -> sputbackc () ou rdbuf () -> sungetc () de retour traits :: eof () à putback () ou unget ()

    Original:

    rdbuf()->sputbackc() or rdbuf()->sungetc() return traits::eof() to putback() or unget()

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • rdbuf () -> pubsync () retourne -1 pour synchroniser (), pour flush (), ou le destructeur de ostream :: sentinelle sur un flux unitbuf

    Original:

    rdbuf()->pubsync() returns -1 to sync(), to flush(), or to the destructor of ostream::sentry on a unitbuf stream

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • Exception est levée au cours d'une opération d'E / S par une fonction membre de la mémoire tampon de flux associé (par exemple sbumpc (), xsputn (), sgetc (), de trop-plein (), etc)

    Original:

    Exception is thrown during an I/O operation by any member function of the associated stream buffer (e.g. sbumpc(), xsputn(), sgetc(), overflow(), etc)

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • Exception est levée dans iword () ou motpasse () (par exemple std :: bad_alloc)

    Original:

    Exception is thrown in iword() or pword() (e.g. std::bad_alloc)

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Paramètres

(Aucun)

Original:

(none)

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Retourne la valeur

true si une erreur irrécupérable s'est produite, false autrement .

Original:

true if a non-recoverable error has occurred, false otherwise.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Exemple

[edit]

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

Voir aussi

ios_base::iostate flags basic_ios accessors
eofbit failbit badbit good() fail() bad() eof() operator bool() operator!()
false false false true false false false true false
false false true false true true false false true
false true false false true false false false true
false true true false true true false false true
true false false false false false true true false
true false true false true true true false true
true true false false true false true false true
true true true false true true true false true