日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

linux下的strerror和perror

發(fā)布時間:2025/6/15 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下的strerror和perror 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

? ? ? ? ? ? ?strerror和perror用于獲取error相關(guān)的錯誤信息,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; }
編譯運(yùn)行:

[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],編譯并運(yùn)行。

[mapan@localhost APUE]$ ./a.out 1111 1111 No such file or directory 1111: No such file or directory這證明argv[1]只表示輸出前面指定的參數(shù),與錯誤碼無關(guān)。perror()輸出的錯誤只與errno有關(guān),與傳入的參數(shù)無關(guān)。




《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的linux下的strerror和perror的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。