admin管理员组文章数量:1405115
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.
1 Answer
Reset to default 0Apparently .scan<'i', int>
is required.
argument_parser.add_argument("--port")
.help("port number")
.required()
.scan<'i', int>();
本文标签: cHow to use argparse with integer argument valuesStack Overflow
版权声明:本文标题:c++ - How to use argparse with integer argument values? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744885264a2630445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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