简体   繁体   English

将perror输出重定向到fprintf(stderr,“”)

[英]Redirect perror output to fprintf(stderr, “ ”)

In case a system call function fails, we normally use perror to output the error message. 如果系统调用函数失败,我们通常使用perror来输出错误消息。 I want to use fprintf to output the perror string. 我想使用fprintf输出perror字符串。 How can I do something like this: 我该怎么做这样的事情:

fprintf(stderr, perror output string here);
#include <errno.h>

fprintf(stderr, "%s\n", strerror(errno));

Note: strerror doesn't apply \\n to the end of the message 注:字符串错误不适\\n在邮件的末尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM