Recently learned CPP (as for why, refer to http://www.cnblogs.com/zhjh256/p/6321972.html), C + + standard library second Edition 5.8.2 section, found that C + + has a corresponding Java Shutdownhook the mechanism to exit the processor, atexit. You can invoke the registered function when you exit the program normally, as follows:
namespace Ns_demo { void printn (); void terminatetest ();}
#include"stdafx.h"#include<iostream>#include"Ns.h"using namespacestd;voidNs_demo::p rintn () {cout<<1<<Endl;}voidns_demo::terminatetest () {cout<<"program is ending ..."<<Endl; System ("Pause");}
" Ns.h " using namespace std; #define Guid_lenint _tmain (int argc, _tchar* argv[]) { atexit (ns_demo::terminatetest); Atexit (ns_demo::terminatetest);}
The same processor is registered two times, it will exit when called two times, do not do a duplicate check, as follows:
Program is ending ... Please press any key to continue ... Program is ending ... Please press any key to continue ...
Exit processor for Java Shutdownhook in C + +