You are here

exit

6 February, 2015 - 16:36

Although exit is technically a pre-defined function, it is covered here because of its common usage in pro gramming. A good example is the opening a file and then testing to see if the file was actually opened. If not, we have an error that usually indicates that we want to pre-maturely stop the execution of the program. Within the C++ programming language the exit function terminates the running of the program and in the process returns an integer value back to the operating system. It fts the definition of branching which is to jump to some other place in the program. In our example the value returned to the operating system is the value of the constant named: EXIT FAILURE.

Example 12.11: C++ source code

inData.open(filename); //Open input fileif (!inData)           //Test to see if file was opened  {  cout  << "nnnnError opening file: "  <<  filename  << "\n\n";  pause();             //Pause - user reads message  exit(EXIT_FAILURE);  //Allows a pre-mature jump to OS  }