Skip to content

snsinfu/cxx-getopt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header-only getopt for C++

C++03 Boost License Build Status

Single-file, header-only library of a POSIX getopt workalike.

#include <getopt.hpp>

// command -v -o arg ...
int main(int argc, char** argv)
{
    cxx::getopt getopt;

    bool verbose = false;
    char const* output = "default";

    for (int opt; (opt = getopt(argc, argv, "vo:")) != -1; ) {
        switch (opt) {
          case 'v':
            verbose = true;
            break;

          case 'o':
            output = getopt.optarg;
            break;

          case '?':
            // Error
        }
    }

    argc -= getopt.optind;
    argv += getopt.optind;

    // Now you can access positional arguments: argv[0], ..., argv[argc - 1]
}

Installation

Just download getopt.hpp into your include directory.

License text is included in the header file and the license is permissive (the Boost License), so you do not need to do anything on redistribution.

Testing

git clone https://github.com/snsinfu/cxx-getopt.git
cd cxx-getopt/tests
make

License

Boost Software License, Version 1.0.

Releases

No releases published

Packages

No packages published

Languages