Exit processor for Java Shutdownhook in C + +

Source: Internet
Author: User

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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.