C++ Tutorial/Development/exit


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Версия от 10:29, 25 мая 2010; Admin (обсуждение | вклад) (1 версия: Импорт контента...)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Using the exit and atexit functions

#include <iostream>
#include <stdlib.h>
using namespace std;
void print( void );
int main()
{
   atexit( print );       // register function print 
   cout << "Enter 1 to terminate program with function exit" 
        << "\nEnter 2 to terminate program normally\n";
   int answer;
   cin >> answer;
   if ( answer == 1 ) {
      cout << "\nTerminating program with function exit\n";
      exit( EXIT_SUCCESS );
   }
   cout << "\nTerminating program by reaching the of main"
        << endl;
   return 0;
}
void print( void )
{
   cout << "Executing function print at program termination\n"
        << "Program terminated" << endl;
}