转: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);
}
运行结果:
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);
}
运行结果:
相关文章推荐
- perror和strerror的区别
- perror 和 strerror 的区别
- perror和strerror的使用和区别
- perror 和 strerror 区别
- perror 和 strerror 区别
- perror()与strerror()的应用及区别 man手册查询
- perror和strerror的区别 http://blog.csdn.net/lalor/article/details/7555019
- errno , perror,strerror
- perror和printf什么区别
- linux系统编程之错误处理:perror,strerror和errno
- 1-6例示strerror和perror
- strerror和perror函数详解
- strerror() 和perror()函数
- linux下错误的捕获:errno、strerror和perror的使用
- 区别stderr,strerror,errno的用法
- perror和strerror的问题
- perror和strerror
- errno , perror,strerror
- perror函数和strerror函数的区别
- perror() 和 strerror()