您的位置:首页 > 其它

转:perror和strerror的区别

2016-08-30 10:35 288 查看
概述:

perror和strerror都是C语言提供的库函数,用于获取与erno相关的错误信息,区别不大,用法也简单。最大的区别在于perror向stderr输出结果,而 strerror向stdout输出结果。

测试代码如下:

[cpp] view plain copy

print?

#include <stdio.h>

#include <string.h>

#include <errno.h>

int main(int argc, char* argv[])

{

FILE *fp;

if ((fp = fopen(argv[1], "r")) == NULL)

{

perror("perror:");

printf("strerror:%s\n", strerror(errno));

}

exit(0);

}

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: