Written by
Niels Moseley
on
on
CXXOPTS example code
Here is some CXXOPTS command line parser example/copy-paste code:
#include <cxxopts.hpp>
#include <string>
int main(int argc, const char *argv[])
{
cxxopts::Options options("Application name", "Application description");
options.add_options()
("h,help", "show help")
("f,file", "file name", cxxopts::value<std::string>())
("v,verbose", "verbose output", cxxopts::value<bool>()->default_value("false"))
;
auto result = options.parse(argc, argv);
if (result.count("help"))
{
std::cout << options.help() << "\n";
return EXIT_FAILURE;
}
if (result.count("file") < 1)
{
std::cout << options.help() << "\n";
return EXIT_FAILURE;
}
std::string fileName = result["file"].as<std::string>();
return EXIT_SUCCESS;
}