std::basic_ios::operator bool
De cppreference.com
<metanoindex/>
<tbody> </tbody> operator void*() const; |
(1) | (até C++11) |
explicit operator bool() const; |
(2) | (desde C++11) |
1)
Retorna um ponteiro nulo se
fail() retornos true, caso contrário, retorna um ponteiro não nulo. Esse ponteiro é implicitamente conversível para bool e pode ser usado em contexto booleano.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)
Retorna
true se o fluxo não tem erros ocorridos e está pronto de operações de E / S. Especificamente, retorna !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.
Este operador faz com que seja possível utilizar correntes e funções que retornam referências a correntes como as condições de circuito, o que resulta na idiomática C + + entrada laços tais como
while(stream >> value) {...} ou while(getline(stream, string)){...}. Tais loops executar corpo do laço apenas se a operação de entrada sucedido.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.
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.
Valor de retorno
true se o fluxo não tem erros, caso contrário false.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.
Exemplo
#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';
}
Saída:
(bool)s is true
1
2
3
(bool)s is false
