Add --verbose, --output, and --count flags to a C++ command-line tool with automatic usage text generation.
Parse positional arguments alongside named flags so users can pass filenames without a flag prefix.
Group command-line options into labeled sections to produce an organized, readable --help message.
cxxopts is a small C++ library that handles command line option parsing. When you write a program and want users to pass flags like --verbose or --file myfile.txt on the command line, this library takes care of reading and interpreting those inputs so you do not have to write that plumbing yourself. The library is header-only, which means you include a single .hpp file in your project and you are done. There is no separate compilation step or external dependency to link against. It follows the standard GNU-style syntax that most command line tools on Linux and macOS already use, so options like --long, --long=value, -a, and grouped short flags like -abc all work as expected. To use it, you create an Options object, add the flags your program accepts (each with a name, description, and optional type like int or string), then call parse with the standard argc and argv arguments your main function receives. After parsing, you can ask for how many times a flag appeared or retrieve its value cast to the correct type. If a flag is unknown or a value cannot be parsed, the library throws a typed exception with a readable message. The library also handles positional arguments, which are values passed without a flag name in front of them. You can collect them individually or gather all remaining ones into a list. Options can be given default values for when the user does not supply them, or implicit values for when a flag is present but no argument follows it. For help output, you can group options into named sections so the printed usage message is organized by category rather than dumped as a flat list. The project is MIT-licensed, available on Homebrew, Conan, and vcpkg, and is included in the Awesome C++ list.
← jarro2783 on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.