c++ – How to use argparse with integer argument values?

I’m getting a std::bad_any_cast exception from the following argument parsing code which uses argparse.

argparse::ArgumentParser argument_parser("program name");
argument_parser.add_argument("--port")
    .help("port number")
    .required();
argument_parser.parse_args(argc, argv);

const auto port_number = argument_parser.get("port");

As far as I’m aware, I don’t need to do anything special for an integer type argument compared with a std::string type argument. (At least I don’t see anything in the README page which suggests this.)

Link to argparse can be found here.

Read more here: Source link