How do I make a C++ console program exit?

Viewed 139581

Is there a line of code that will terminate the program?

Something like python's sys.exit()?

13 Answers

This SO post provides an answer as well as explanation why not to use exit(). Worth a read.

In short, you should return 0 in main(), as it will run all of the destructors and do object cleanup. Throwing would also work if you are exiting from an error.

throw back to main which should return EXIT_FAILURE,

or std::terminate() if corrupted.

(from Martin York's comment)

Related