C++ Tutorial/Development/exit

Материал из C\C++ эксперт
Версия от 13:29, 25 мая 2010; Admin (обсуждение | вклад) (1 версия: Импорт контента...)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Using the exit and atexit functions

<source lang="cpp">#include <iostream>

  1. 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;

}</source>