fig18_04.cpp

来自「经典vc教程的例子程序」· C++ 代码 · 共 34 行

CPP
34
字号
// Fig. 18.4: fig18_04.cpp
// Using the exit and atexit functions 
#include <iostream.h>
#include <stdlib.h>

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;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?