Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      EXIT_SUCCESS, EXIT_FAILURE

      From cppreference.com
      <cpp‎ |utility‎ |program
       
       
      Utilities library
       
       
      Defined in header<cstdlib>
      #define EXIT_SUCCESS /*implementation defined*/
      #define EXIT_FAILURE /*implementation defined*/

      TheEXIT_SUCCESS andEXIT_FAILURE macros expand into integral constant expressions that can be used as arguments to thestd::exit function (and, therefore, as the values to return from themain function), and indicate program execution status.

      A freestanding implementation is required to provideEXIT_SUCCESS andEXIT_FAILURE.

      (since C++23)
      Constant Description
      EXIT_SUCCESS successful execution of a program
      EXIT_FAILURE unsuccessful execution of a program

      [edit]Notes

      BothEXIT_SUCCESS and the value zero indicate successful program execution status (seestd::exit), although it is not required thatEXIT_SUCCESS equals zero.

      AlthoughEXIT_SUCCESS andEXIT_FAILURE are required to be freestanding since C++23, they are not required to be available in a freestanding C implementation.

      [edit]Example

      Run this code
      #include <cstdlib>#include <iostream> int main(int argc,char* argv[]){if(argc<=1){std::cout<<"At least one command-line argument required\n";return EXIT_FAILURE;} std::cout<< argv[1]<<'\n';return EXIT_SUCCESS;}

      Possible output:

      The quick brown fox jumps over the lazy cat

      [edit]See also

      C documentation forEXIT_SUCCESS,EXIT_FAILURE
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/program/EXIT_status&oldid=178763"

      [8]ページ先頭

      ©2009-2025 Movatter.jp