std::basic_ios::operator bool
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> operator void*() const; |
(1) | (avant C++11) |
explicit operator bool() const; |
(2) | (depuis C++11) |
1)
Retourne un pointeur nul si le rendement
fail() true, sinon retourne un pointeur non NULL. Ce pointeur est implicitement convertible en bool et peut tre utilis dans un contexte boolen .Original:
Returns a null pointer if
fail() returns true, otherwise returns a non-null pointer. This pointer is implicitly convertible to bool and may be used in boolean context.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
Retours
true si le flux n'a pas eu lieu erreurs et il est prt d'oprations d'E / S. Plus prcisment, les rendements !fail() . Original:
Returns
true if the stream has no errors occurred and is ready of I/O operations. Specifically, returns !fail(). The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Cet oprateur permet d'utiliser les flux et les fonctions qui retournent des rfrences aux cours d'eau que les conditions de boucle, ce qui entrane l'idiomatique C + + boucles d'entre tels que
while(stream >> value) {...} ou while(getline(stream, string)){...}. Ces boucles d'excuter le corps de la boucle que si l'opration d'entre russi .Original:
This operator makes it possible to use streams and functions that return references to streams as loop conditions, resulting in the idiomatic C++ input loops such as
while(stream >> value) {...} or while(getline(stream, string)){...}. Such loops execute the loop's body only if the input operation succeeded.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Paramtres
(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.
You can help to correct and verify the translation. Click here for instructions.
Retourne la valeur
true si le flux a aucune erreur n'est survenue, false autrement .Original:
true if the stream has no errors 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.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#include <iostream>
#include <sstream>
int main()
{
std::istringstream s("1 2 3 error");
int n;
std::cout << std::boolalpha << "(bool)s is " << (bool)s << '\n';
while (s >> n) {
std::cout << n << '\n';
}
std::cout << std::boolalpha << "(bool)s is " << (bool)s << '\n';
}
Rsultat :
(bool)s is true
1
2
3
(bool)s is false
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 |