nazerke
11/28/2019 - 12:11 PM

error handling with strerror

#include <cstdio>
using namespace std;

int main()
{
    printf("errno is: %d\n",errno);
    printf("Erasing file foo.bar\n");
    remove("foo.bar");
    printf("errno is: %d\n",errno);
    const char * errstr = strerror(errno);
    printf("Tried to erase a file and this happened: %s\n",errstr);
    //alternatively, perror(errno);
    return 0;
}