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

std::_Exit

Defined in header <cstdlib>

[noreturn] void _Exit( int exit_code );

(since C++11)

导致正常程序终止而不完全清除资源。

不调用具有自动、线程本地和静态存储时间的变量的析构函数。传递给std::at_quick_exit()std::atexit()都不叫。是否关闭文件等开放资源是实现定义的。

如果exit_code0EXIT_SUCCESS,表示成功终止的实现定义状态返回到主机环境。如果exit_codeEXIT_FAILURE,实现定义的状态,指示不成功终止,返回。在其他情况下,返回实现定义的状态值。

参数

exit_code

-

exit status of the program

返回值

%280%29

例外

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <iostream>
 
class Static {
public:
    ~Static() 
    {
        std::cout << "Static dtor\n";
    }
};
 
class Local {
public:
    ~Local() 
    {
        std::cout << "Local dtor\n";
    }
};
 
Static static_variable; // dtor of this object will *not* be called
 
void atexit_handler()
{
    std::cout << "atexit handler\n";
}
 
int main()
{
    Local local_variable; // dtor of this object will *not* be called
 
    // handler will *not* be called
    const int result = std::atexit(atexit_handler);
 
    if (result != 0) {
        std::cerr << "atexit registration failed\n";
        return EXIT_FAILURE;
    }
 
    std::cout << "test" << std::endl; // flush from std::endl
        // needs to be here, otherwise nothing will be printed
    std::_Exit(EXIT_FAILURE);
}

二次

产出:

二次

代码语言:javascript
复制
test

二次

另见

abort

causes abnormal program termination (without cleaning up) (function)

exit

causes normal program termination with cleaning up (function)

c文件[医]出口

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

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

扫码关注腾讯云开发者

领取腾讯云代金券