std::basic_ios::operator bool
提供: 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. |
operator void*() const; |
(1) | (C + + 11時まで) |
explicit operator bool() const; |
(2) | (C + + 11以来) |
fail()true返し、そうでなければ、非ヌルポインタを返す場合はnullポインタを返します。このポインタはboolに暗黙的に変換し、ブールコンテキストで使用されるかもしれません.
2) 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.
戻りtrueストリームにエラーがない場合が発生しており、I / O操作の準備ができています。具体的には、!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.
この演算子は、ループ条件としてストリームへの参照を返すストリームおよび関数を使用することが可能になり、慣用的なC + +入力の結果は、このようなwhile(stream >> value) {...}またはwhile(getline(stream, string)){...}としてループします。入力操作が成功した場合にのみ、そのようなループは、ループの本体を実行.
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.
目次 |
[編集] パラメータ
(なし)
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.
[編集] 値を返します
trueストリームはエラーが発生しなかった場合には、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.
[編集] 例
#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'; }
Output:
(bool)s is true 1 2 3 (bool)s is false
[編集] も参照してください
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 |