std:: perror
From cppreference.net
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
C-style I/O
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstdio>
|
||
|
void
perror
(
const
char
*
s
)
;
|
||
将当前存储在系统变量 errno 中的错误代码以文本描述形式输出到 stderr 。
描述由以下组件拼接而成:
- 由 s 指向的以空字符结尾的字节字符串的内容,后跟 ": " (除非 s 是空指针或 s 指向的字符是空字符)。
-
描述存储在
errno中的错误代码的实现定义错误消息字符串,后跟 ' \n ' 。该错误消息字符串与 std:: strerror ( errno ) 的结果相同。
目录 |
参数
| s | - | 指向以空字符结尾的说明性字符串的指针 |
返回值
(无)
示例
运行此代码
#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
参见
|
扩展为POSIX兼容的线程局部错误编号变量的宏
(宏变量) |
|
|
返回给定错误代码的文本描述
(函数) |
|
|
C文档
关于
perror
|
|