errno
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <cerrno> 中定义
|
||
| #define errno /*implementation-defined*/ |
||
errno是一个宏,扩展到static(至 C++11)/线程local(C++11 起)修改的左值的类型int。一些标准库函数表示的正整数写入errno的错误。通常情况下,errno<cerrno>为宏常量开始,其次是大写字母或数字与字母E中列出的错误代码,.原文:
errno is a preprocessor macro that expands to a static(至 C++11) / thread-local(C++11 起) modifiable lvalue of type int. Several standard library functions indicate errors by writing positive integers to errno. Typically, the value of errno is set to one of the error codes, listed in <cerrno> as macro constants that begin with the letter E, followed by uppercase letters or digits.的价值
errno是0在程序启动时,,虽然库函数可以写正整数errno是否发生了错误,不会储存库函数0在errno.原文:
The value of
errno is 0 at program startup, and although library functions are allowed to write positive integers to errno whether or not an error occurred, library functions never store 0 in errno.[编辑] 示例
#include <iostream> #include <cmath> #include <cerrno> #include <cstring> int main() { double not_a_number = std::log(-1.0); if (errno == EDOM) { std::cout << "log(-1) failed: " << std::strerror(errno) << '\n'; } }
输出:
log(-1) failed: Numerical argument out of domain
[编辑] 另请参阅
| 宏为标准的POSIX兼容的错误条件 原文: macros for standard POSIX-compatible error conditions (常量宏) | |
| 显示一个字符串相应的电流误差stderr 原文: displays a character string corresponding of the current error to stderr (函数) | |
| 返回一个给定的错误代码的文本版本 原文: returns a text version of a given error code (函数) | |