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<int>("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.
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<int>("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.
Apparently .scan<'i', int>
is required.
argument_parser.add_argument("--port")
.help("port number")
.required()
.scan<'i', int>();
get<int>("--port")
? See this example code: github/p-ranav/… – Yksisarvinen Commented Mar 8 at 21:05scan
github/p-ranav/… – Alan Birtles Commented Mar 8 at 21:08