我可以使用perror
打印出人类可读的errno版本,如下所示:
#include <errno.h>
#include <stdio.h>
int main(void) {
FILE *fp = fopen("file.txt", "r");
if (fp == NULL) {
perror("Unable to open file");
return -1;
}
fclose(fp);
return 0;
}
这也适用于我的实现:
#include <stdio.h>
int main(void) {
FILE *fp = fopen("file.txt", "r");
if (fp == NULL) {
perror("Unable to open file");
return -1;
}
fclose(fp);
return 0;
}
使用perror
而不包括<errno.h>
是不标准的吗?