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

前端 未结 13 2470
执笔经年
执笔经年 2020-12-03 16:43

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

Something like python\'s sys.exit()?

13条回答
  •  难免孤独
    2020-12-03 17:20

    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.

提交回复
热议问题