perror
在头文件<stdio.h>中定义 | | |
---|---|---|
void perror(const char * s); | | |
打印到stderr
由s
(由s
空指针指向的)以空字符结尾的字符串的内容,后跟两个字符": "
,后面跟着实现定义的错误消息,描述当前存储在系统变量中的错误代码errno
(与输出strerror(errno)
),然后'\n'
。
参数
s | - | 指向带有解释性消息的以空字符结尾的字符串 |
---|
返回值
(none).
例
#include <stdio.h>
int main(void)
{
FILE* f = fopen("non_existent", "r");
if (f == NULL) {
perror("open()");
} else {
fclose(f);
}
}
输出:
open(): No such file or directory
参考
- C11 standard (ISO/IEC 9899:2011):
- 7.21.10.4 The perror function (p: 339)
- C99 standard (ISO/IEC 9899:1999):
- 7.19.10.4 The perror function (p: 305)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.9.10.4 The perror function
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com