Correct usage of exit() in c++?

后端 未结 6 1209
再見小時候
再見小時候 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 11:05

    From main there's no difference in exit(1) or return 1. You use a return/exit value of 0 for success and non 0 for failure.

    If your subroutine is a library routine, which is used somewhere else, it should return control to main with some return code or an exception. Otherwise it's your choice, if you exit or return.

    In either case, it's good practice to document what the function does, be it exit, return code or exception.

提交回复
热议问题