perror和printf的区别
我们大多都使用printf来打印一些信息,其它的接口都比较少用。perror函数用的比较少,但是用起来调试比printf打印更加详细
注意:perror不能带参数,printf可以带参数 printf例子: #includeint main(void){ FILE *fp; fp = fopen(\”/home/book/test_file\”, \”r+\”); if (NULL == fp) { printf(\”fopen error!\\n\”); } return 0;}
输出结果:
fopen error! perror例子: #include#include #include int main(void){ FILE *fp; fp = fopen(\”/home/book/test_file\”,\”r+\”); if (NULL == fp) { perror(\”fopen error\”); } return 0;}
输出结果:
fopen error: No such file or directory
相比之下,perror会打印更详细的错误log信息
39613034
《printfarr,为什么是printf不是print》来自互活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...