mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 14:44:40 +00:00
Argument Parser for Modern C++ | Fix Xmake and Modules
src | ||
tests | ||
.gitignore | ||
LICENSE | ||
README.md |
Argument Parser
Simple Optional Arguments
#include <argparse.hpp>
int main(int argc, char *argv[]) {
argparse::ArgumentParser program("main");
program.add_argument("--config")
.help("configuration file")
.default_value(std::string("config.yml"));
program.add_argument("-n", "--num_iterations")
.help("The list of input files")
.action([](const std::string& value) { return std::stoi(value); });
program.parse(argc, argv);
std::string config = program.get("--config");
int num_iterations = program.get<int>("-n");
return 0;
}
List of arguments
#include <argparse.hpp>
int main(int argc, char *argv[]) {
argparse::ArgumentParser program("main");
program.add_argument("--input_files")
.help("The list of input files")
.nargs(3);
program.parse(argc, argv);
std::vector<std::string> files = program.get<std::vector<std::string>>("--input_files");
return 0;
}