Correct usage of exit() in c++?

后端 未结 6 1202
再見小時候
再見小時候 2021-02-12 10:31

I have written a simple application that reads a data file, parses the text and then does some processing on that data. The data file is opened in my main() function. Is it good

6条回答
  •  一向
    一向 (楼主)
    2021-02-12 10:59

    There are two aspects. One is the interest of deciding to stop the program at the place you want to use exit, the other is the use of exit. Mat's answer covers the first.

    For the second, exit is usually a bad choice in C++. The reason is that it does some cleanup (functions registered with atexit and that sometimes include destructors of some objects of static storage duration), but not all of them (destructors of objects on the stack) and in my experience you either want all of it or none.

提交回复
热议问题