网上搜索加以整理能够实现
//在main函数执行完之后执行一段代码
#include <iostream>
using namespace std;void f1()
{
cout << "f1()" << endl;
}
void f2()
{
cout << "f2()" << endl;
}
void f3()
{
cout << "f3()" << endl;
}
void f4()
{
cout << "f4()" << endl;
}
int main()
{
atexit(f1);
atexit(f2);
atexit(f3);
atexit(f4);
cout << "main function." << endl;
return 0;
}
//在main函数执行之前执行一段代码
#include<iostream>
using namespace std;
class A{
public:
A();
};
A::A(){
cout<<"ni hao 1"<<endl;
}
A a1;
int main()
{
cout<<"ni hao 2"<<endl;
return 0;
}