std::basic_ios::operator!
Da 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. |
bool operator!()const; | ||
Retorna true se ocorreu um erro no fluxo associado. Especificamente, os retornos true se
badbit
ou failbit
é definido em 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.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar]Parâmetros
(Nenhum)
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.
[editar]Valor de retorno
true se um erro ocorreu, false outra forma.
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.
You can help to correct and verify the translation. Click here for instructions.
[editar]Exemplo
#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";returnEXIT_FAILURE;} // typical C++ I/O loop uses the return value of the I/O function// as the loop controlling condition, operator bool() is used herefor(int n; file >> n;){std::cout<< n <<' ';}std::cout<<'\n'; if(file.bad())std::cout<<"I/O error while reading\n";elseif(file.eof())std::cout<<"End of file reached successfully\n";elseif(file.fail())std::cout<<"Non-integer data encountered\n";}
[editar]Veja também
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 |