std::basic_ios::bad
性病:基本[医]监督办::坏
bool bad() const; | | |
---|
回报true
如果关联的流上发生了不可恢复的错误。具体来说,返回true
如果badbit
设为rdstate()
...
见ios_base::iostate
的条件列表badbit
...
参数
%280%29
返回值
true
如果发生了不可恢复的错误,false
否则。
例
二次
#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";
return EXIT_FAILURE;
}
// typical C++ I/O loop uses the return value of the I/O function
// as the loop controlling condition, operator bool() is used here
for(int n; file >> n; ) {
std::cout << n << ' ';
}
std::cout << '\n';
if (file.bad())
std::cout << "I/O error while reading\n";
else if (file.eof())
std::cout << "End of file reached successfully\n";
else if (file.fail())
std::cout << "Non-integer data encountered\n";
}
二次
另见
下表显示basic_ios
访问器%28good()
,,,fail()
的所有可能组合的%29。ios_base::iostate
旗帜:
ios_base::iostate flags | basic_ios accessors |
---|---|
eofbit | failbit |
false | false |
false | false |
false | true |
false | true |
true | false |
true | false |
true | true |
true | true |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。