Obtaining error messages in C++
Hi! How does one get access to the standard error messages in C++?
In C you can get the error message from strerror(), provided you have the error code. How can something similar be achieved using the iostreams library in C++? I thought that the exception messages could be useful but doesn't seem like it. "Underflow error reading the file" isn't too helpful :-/ And looking for "c++ error message" on the internet gets only pages on compiler error messages :rolleyes:
I'm looking for the equivalent of:
Code:
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(void)
{
// pretend a directory is a file
FILE* f = fopen("/", "r");
getc(f);
// print the resulting error message
char* error_message = strerror(errno);
// output: Oopsie: Is a directory
printf("Oopsie: %s\n", error_message);
return 0;
}