J
Johannes Bauer
Hello group,
coming from C, I'm used to somthing like this when opening a file
const char *foobar = "this.txt";
FILE *f;
f = fopen(foobar, "r");
if (!f) {
fprintf(stderr, "Couldn't open %s: %s\n", foobar, strerror(errno));
exit(EXIT_FAILURE);
}
translating that somewhat to C++ yields me with
const char *foobar = "this.txt";
std::ifstream f(foobar);
if (!f) {
throw GenericException("Couldn't open file.");
}
So I can detect that opening the file wasn't successful, but I don't
know *why* (i.e. permissions, no such file or directory, etc.). My guess
is that strerror and errno still do what I expect them to do, however I
think that would be a very C-way to solve things.
How can I accomplish strerror(errno) on the std::ifstream with C++ means?
Greetings,
Johannes
coming from C, I'm used to somthing like this when opening a file
const char *foobar = "this.txt";
FILE *f;
f = fopen(foobar, "r");
if (!f) {
fprintf(stderr, "Couldn't open %s: %s\n", foobar, strerror(errno));
exit(EXIT_FAILURE);
}
translating that somewhat to C++ yields me with
const char *foobar = "this.txt";
std::ifstream f(foobar);
if (!f) {
throw GenericException("Couldn't open file.");
}
So I can detect that opening the file wasn't successful, but I don't
know *why* (i.e. permissions, no such file or directory, etc.). My guess
is that strerror and errno still do what I expect them to do, however I
think that would be a very C-way to solve things.
How can I accomplish strerror(errno) on the std::ifstream with C++ means?
Greetings,
Johannes