C++ 中_onexit()函数

这个函数可以实现在main主函数执行完毕之后,才执行的代码。

 (1)使用格式:_onexit(int fun()) ,其中函数fun()必须是带有int类型返回值的无参数函数;

  (2)_onexit() 包含在头文件cstdlib中,cstdlib为c语言中的库函数;

  (3)无论函数_onexit() 放到main中任意位置,它都是最后执行。
 

#include <iostream>
#include <cstdlib>
using namespace std;
int func1(),func2(),func3();

int main(){

   _onexit(func2);
   _onexit(func1);                   
   _onexit(func3);
    cout<<"First Line"<<endl;
    cout<<"Second Line"<<endl;
}

int func1()
{
    cout<<"fun1()  executed!"<<endl;
    return 0;
}

int func2()
{
    cout<<"fun2()  is"<<endl;
    return 0;
}
int func3()
{
    cout<<"fun3()  This "<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值