您的位置:首页 > 编程语言 > C语言/C++

c++学习之旅 (在main函数执行前执行一段代码和在main函数执行之后执行一段代码)

2015-04-12 17:13 423 查看
网上搜索加以整理能够实现

//在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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐