mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
It is possible to bind arguments to a variable storing their value, as an alternative to explicitly calling ``program.get<T>(arg_name)`` or ``program[arg_name]`` This is currently implementeted for variables of type ``bool`` (this also implicitly calls ``flag()``), ``int``, ``double``, ``std::string`` and ``std::vector<std::string>``. If the argument is not specified in the command line, the default value (if set) is set into the variable. ```cpp bool flagvar = false; program.add_argument("--flagvar").store_into(flagvar); int intvar = 0; program.add_argument("--intvar").store_into(intvar); double doublevar = 0; program.add_argument("--doublevar").store_into(doublevar); std::string strvar; program.add_argument("--strvar").store_into(strvar); std::vector<std::string> strvar_repeated; program.add_argument("--strvar-repeated").append().store_into(strvar_repeated); std::vector<std::string> strvar_multi_valued; program.add_argument("--strvar-multi-valued").nargs(2).store_into(strvar_multi_valued); ``` |
||
---|---|---|
.. | ||
argparse |