当前位置:
首页 >
linux下的strerror和perror
发布时间:2025/6/15
31
豆豆
生活随笔
收集整理的这篇文章主要介绍了
linux下的strerror和perror
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
strerror和perror用于获取error相关的错误信息,strerror接受一个int,perror接受一个字符串。
#include <stdio.h> #include <errno.h> #include <string.h>int main(int argc,char *argv[]) {printf("%s\n",argv[0]);errno=2;printf("%s\n",strerror(errno));perror(argv[0]);return 0; }编译运行: [mapan@localhost APUE]$ ./a.out ./a.out No such file or directory ./a.out: No such file or directory argv[0]=./a.out,把上述代码中的argv[0]换成argv[1],编译并运行。 [mapan@localhost APUE]$ ./a.out 1111 1111 No such file or directory 1111: No such file or directory这证明argv[1]只表示输出前面指定的参数,与错误码无关。perror()输出的错误只与errno有关,与传入的参数无关。
总结
以上是生活随笔为你收集整理的linux下的strerror和perror的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 实战测试SO_REUSEADDR选项
- 下一篇: linux下多线程实现服务端