Skip to content

Quick start

jarro2783 edited this page Oct 13, 2014 · 5 revisions

First, you only need to include:

#include <cxxopts.hpp>

Then, make an instance of cxxopts::Options:

cxxopts::Options options;

You can then add options like so:

options.add_options()
  ("f,file", "File", cxxopts::value<std::string>());

The options can be specified with a short option, which is a single character, or a long option, which is two or more characters, or both, separated by a comma; the short option must come first.

To parse the command line arguments, simple write:

options.parse(argc, argv);

This will parse the arguments and modify argc and argv, removing all recognised arguments.

Clone this wiki locally