同步操作将从 zhipeng515/cxxopts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
This is a lightweight C++ option parser library, supporting the standard GNU style syntax for options.
Options can be given as:
--long
--long=argument
--long argument
-a
-ab
-abc argument
where c takes an argument, but a and b do not.
Additionally, anything after --
will be parsed as a positional argument.
#include <cxxopts.hpp>
Create a cxxopts::Options instance.
cxxopts::Options options("MyProgram", "One line description of MyProgram");
Then use add_options
.
options.add_options()
("d,debug", "Enable debugging")
("f,file", "File name", cxxopts::value<std::string>())
;
Options are declared with a long and an optional short option. A description must be provided. The third argument is the value, if omitted it is boolean. Any type can be given as long as it can be parsed, with operator>>.
To parse the command line do:
options.parse(argc, argv);
To retrieve an option use options.count("option")
to get the number of times
it appeared, and
options["opt"].as<type>()
to get its value. If "opt" doesn't exist, or isn't of the right type, then an exception will be thrown.
Options can be placed into groups for the purposes of displaying help messages.
To place options in a group, pass the group as a string to add_options
. Then,
when displaying the help, pass the groups that you would like displayed as a
vector to the help
function.
Positional arguments can be optionally parsed into one or more options. To set up positional arguments, call
options.parse_positional({"first", "second", "last"})
where "last" should be the name of an option with a container type, and the others should have a single value.
An option can be declared with a default or an implicit value, or both.
A default value is the value that an option takes when it is not specified on the command line. The following specifies a default value for an option:
cxxopts::value<std::string>()->default_value("value")
An implicit value is the value that an option takes when it is given on the command line without an argument. The following specifies an implicit value:
cxxopts::value<std::string>()->implicit_value("implicit")
If an option had both, then not specifying it would give the value "value"
,
writing it on the command line as --option
would give the value "implicit"
,
and writing --option=another
would give it the value "another"
.
This is a header only library.
The only build requirement is a C++ compiler that supports C++11 regular expressions. For example GCC >= 4.9 or clang with libc++.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。