在主函数main()之后再执行另外一个函数的方法

来源:互联网 发布:淘宝客开通 编辑:程序博客网 时间:2024/05/21 00:51
//在主函数main()之后再执行另外一个函数的方法://在主函数中通过注册函数_onexit()注册一个函数,//被注册函数的返回值必须是int类型的,且不能含有参数#include <iostream>using namespace std;int func();int main(){/***_onexit(func)放在下面的任意行位置,其参数函数总是在主函数执行之后执行***///_onexit(func);cout << "this is firstly executed!" << endl;_onexit(func);return 0;}int func(){cout << "this is secondly executed after the main() function!" << endl;return 0;}


执行结果如下: