首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

perror

在头文件<stdio.h>中定义

?

?

void perror(const char * s);

?

?

打印到stderrs(由s空指针指向的)以空字符结尾的字符串的内容,后跟两个字符": ",后面跟着实现定义的错误消息,描述当前存储在系统变量中的错误代码errno(与输出strerror(errno)),然后'\n'

参数

s

-

指向带有解释性消息的以空字符结尾的字符串

返回值

(none).

代码语言:javascript
复制
#include <stdio.h>
 
int main(void)
{
    FILE* f = fopen("non_existent", "r");
    if (f == NULL) {
        perror("open()");
    } else {
        fclose(f);
    }
}

输出:

代码语言:javascript
复制
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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com