C++中设置Main函数结束后执行的代码_艾孜尔江撰
原创
©著作权归作者所有:来自51CTO博客作者已注销的原创作品,请联系作者获取转载授权,否则将追究法律责任
#include <iostream>
#include <cstdlib>
using namespace std;
int func1(),func2(),func3();
int main(int argc,char * argv[])
{
_onexit(func2); //函数注册时入栈,调用时出栈
_onexit(func1);
_onexit(func3);
cout<<"First Line"<<endl;
cout<<"Second Line"<<endl;
}
int func1()
{
cout<<"fun1() is executed!"<<endl;
return 0;
}
int func2()
{
cout<<"fun2() is executed!"<<endl;
return 0;
}
int func3()
{
cout<<"fun3() is executed!"<<endl;
return 0;
}
效果