Cxxopts is a lightweight C++ library for parsing command-line options and positional arguments using familiar GNU-style flags. It maps values through standard stream extraction and groups options for help output.
Overview
Cxxopts helps C++ programs accept long and short options, optional arguments, and trailing positional parameters without rewriting ad hoc argv handling on every project. Options are declared with descriptions, default values, and optional help groups so generated usage text stays organized.
Parsing leaves the original argc and argv buffers untouched, and results can outlive the parser object. Typed getters rely on operator>> conversions, with exceptions for malformed definitions or unreadable values. Unrecognized tokens can be collected instead of failing immediately when you opt in.
Positional mode maps bare arguments onto declared options, including list-style tail positionals for filenames or similar sequences. Help output can show every group or filter to specific sections, which suits CLIs that expose many advanced flags beside everyday commands.
Key features
- GNU-style long and short flags
- Typed option values via iostreams
- Non-modifying argc and argv parsing
- Grouped help sections
- Positional argument mapping
- Optional unrecognized arg capture
- Exception-based error reporting
Use cases
- Adding CLI flags to C++ tools
- Parsing mixed flags and positionals
- Generating structured help text
- Migrating legacy argv parsers