std::_Exit
| Defined in header <cstdlib> |  |  | 
|---|---|---|
| [noreturn] void _Exit( int exit_code ); |  | (since C++11) | 
导致正常程序终止而不完全清除资源。
不调用具有自动、线程本地和静态存储时间的变量的析构函数。传递给std::at_quick_exit()或std::atexit()都不叫。是否关闭文件等开放资源是实现定义的。
如果exit_code是0或EXIT_SUCCESS,表示成功终止的实现定义状态返回到主机环境。如果exit_code是EXIT_FAILURE,实现定义的状态,指示不成功终止,返回。在其他情况下,返回实现定义的状态值。
参数
| exit_code | - | exit status of the program | 
|---|
返回值
%280%29
例外
noexcept规格:
noexcept
例
二次
#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);
}二次
产出:
二次
test二次
另见
| abort | causes abnormal program termination (without cleaning up) (function) | 
|---|---|
| exit | causes normal program termination with cleaning up (function) | 
c文件[医]出口
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

