命名空间
变体
操作

std::perror

来自 cppreference.cn
< cpp‎ | io‎ | c
 
 
 
 
定义于头文件 <cstdio>
void perror( const char *s );

将当前存储在系统变量 errno 中的错误代码的文本描述打印到 stderr

描述由连接以下组件形成

  • s 指向的空终止字节字符串的内容,后跟 ": "(除非 s 是空指针或由 s 指向的字符是空字符)。
  • 实现定义的错误消息字符串,描述存储在 errno 中的错误代码,后跟 '\n'。错误消息字符串与 std::strerror(errno) 的结果相同。

内容

[edit] 参数

s - 指向带有解释性消息的空终止字符串的指针

[edit] 返回值

(无)

[edit] 示例

#include <cerrno>
#include <cmath>
#include <cstdio>
 
int main()
{
    double not_a_number = std::log(-1.0);
    if (errno == EDOM)
        std::perror("log(-1) failed");
    std::printf("%f\n", not_a_number);
}

可能的输出

log(-1) failed: Numerical argument out of domain
nan

[edit] 参见

宏,展开为 POSIX 兼容的线程局部错误号变量
(宏变量)[edit]
返回给定错误代码的文本版本
(函数) [edit]
C 文档 关于 perror