C++中设置Main函数结束后执行的代码_艾孜尔江撰

#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;
}



效果
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210612210945243.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Mzg2NzI0Mg==,size_16,color_FFFFFF,t_70)

posted @ 2021-06-12 21:14  艾孜尔江  阅读(117)  评论(0)    收藏  举报