Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::atexit

 

std::atexit is an STL function to specify which functions must be called upon program termination (in a LIFO fashion).

 

std::atexit is defined in cstdlib.h.

 

#include <cstdlib>
#include <iostream>

void MyExit1()
{
  std::cout << "Exit 1\n";
}

void MyExit2()
{
  std::cout << "Exit 2\n";
}

int main()
{
  std::atexit(MyExit1);
  std::atexit(MyExit2);
}

 

Screen output:

 

Starting MyFolder/MyMain
Exit 2
Exit 1
/MyFolder/MyMain exited with code 0

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict