◐ Shell
clean mode source ↗

std::basic_ios::fail — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Retours true si une erreur s'est produite sur le flux associé. Plus précisément, les rendements true si badbit ou failbit est situé dans rdstate() .

Original:

Returns true if an error has occurred on the associated stream. Specifically, returns true if badbit or failbit 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.

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 s'est produite, false autrement .

Original:

true if an 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

chèques pour une erreur de fichier

Original:

checks for a file error

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


(fonction) [edit]