Hello everybody. The code below tries to read data from an empty file. I catch the exception but it reads
basic_ios::clear
.
What exactly does it mean? Thanks in advance.
I think I'm interpreting this the wrong way because I'd rather expect a human-readable error string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <cstdlib>
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
std::ifstream fempty("emptyfile.txt"); // this file contains nothing
fempty.exceptions(std::ifstream::badbit | std::ifstream::failbit);
try {
char whatever[80];
fempty.read(whatever, 80);
}
catch (std::ifstream::failure &ex) {
std::cout << ex.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|
Last edited on
The actual message is implementor defined, but that is an on odd message.
VS 2010 gives: ios_base::failbit set
This is at least a bit more informative.
Last edited on