Unexpected exception in std::ifstream
问题 Experimenting with I/O I get an exception where no exception should have been thrown: #include <iostream> #include <fstream> int main() { std::ifstream f("/tmp"); std::cout << "Exception Flags: " << f.exceptions() << std::endl; if(f >> std::ws) std::cout << "This will not succeed" << std::endl; else std::cout << "Ok - it fails" << std::endl; return 0; } But the output is: Exception Flags: 0 terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_filebuf: