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

errno

Defined in header <cerrno>

#define errno /*implementation-defined*/

errno用于错误指示的预处理宏。它扩展到静态%28,直到C++11%29线程-自C++11%29类型可修改的lvalue以来,本地%28int...

几个标准库函数通过将正整数写入errno。通常情况下,errno中列出的错误代码之一。<cerrno>作为以字母开头的宏常量E后面跟着大写字母或数字。

价值errno​0​在程序启动时,尽管允许库函数将正整数写入errno无论是否发生错误,库函数都不会存储​0​errno...

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <clocale>
 
int main()
{
    double not_a_number = std::log(-1.0);
    if (errno == EDOM) {
        std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
        std::setlocale(LC_MESSAGES, "de_DE.utf8");
        std::cout << "Or, in German, " << std::strerror(errno) << '\n';
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
log(-1) failed: Numerical argument out of domain
Or, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches

二次

另见

E2BIG, EACCES, ..., EXDEV

macros for standard POSIX-compatible error conditions (macro constant)

perror

displays a character string corresponding of the current error to stderr (function)

strerror

returns a text version of a given error code (function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券