(fstreamTest)がチェックするものは何ですか?特定のフラグをチェックしていますか?
fstream testFile;
testFile.open("test.txt", ios::in);
if (testFile)
cout << "This if statement is true";
Cがif(testfile)
からtrue
を返すためには何をチェックする++のでしょうか? testFile.goodbit()
が本当ですか?
(fstreamTest)がチェックするものは何ですか?特定のフラグをチェックしていますか?
fstream testFile;
testFile.open("test.txt", ios::in);
if (testFile)
cout << "This if statement is true";
Cがif(testfile)
からtrue
を返すためには何をチェックする++のでしょうか? testFile.goodbit()
が本当ですか?
前述のように定義... http://en.cppreference.com/w/cpp/io/basic_ios/operator_boolまたはhttp://www.cplusplus.com/reference/ios/ios/operator_bool/を検索できます。最後に、trueまたはfalseを返すfstreamクラスのメソッドを呼び出します。
法上のドキュメントは言う:
Returns true if the stream has no errors occurred and is ready
of I/O operations. Specifically, returns !fail()
ドキュメントの別のバージョンは言う:
Returns whether an error flag is set (either failbit or badbit).
Notice that this function does not return the same as member good,
but the opposite of member fail.
(テストファイル)の場合からtrueを返すためにのためのC++のチェックを行いますか?ストリームにエラーがないかどうか
チェック:cppreferenceから
。
1)fail()
がtrueを返す場合はnullポインタを返し、そうでない場合はnull以外のポインタを返します。この ポインタは暗黙的にbool
に変換可能であり、ブール型 コンテキストで使用できます。 (C++11
まで)
2)ストリームにエラーがなく、 I/O操作の準備ができている場合は、true
を返します。具体的には、!fail()
を返します。
1)operator void*() const;
(までC++ 11)
2)explicit operator bool() const;
(以降C++ 11)
(C++11
ため)ストリームは、それが返すエラーがない場合true
、それ以外の場合はfalse
を返します。
while(stream >> value) {
...
}
C++ 11と2がそれを超えるまで1)が適用されることに言及する価値があります。 –
http://en.cppreference.com/w/cpp/io/basic_ios/operator_bool –
http://www.cplusplus.com/reference:
これにより、のようなものをやってます/ ios/ios/operator_bool/ – ForceBru