Templatized C++ Command Line Parser Library

Get Templatized C++ Command Line Parser at SourceForge.net. Fast, secure and Free Open Source software downloads

TCLAP is a small, flexible library that provides a simple interface for defining and accessing command line arguments. It was initially inspired by the user friendly CLAP library. The difference is that this library is templatized, so the argument class is type independent. Type independence avoids identical-except-for-type objects, such as IntArg, FloatArg, and StringArg. While the library is not strictly compliant with the GNU or POSIX standards, it is close.

TCLAP supports C++98 and later with version 1.4, and C++20 and later with version 1.6. It is known to work on Linux, MacOS X, Windows, and Solaris platforms. The library is implemented entirely in header files making it easy to use and distribute with other software. It is licensed under the MIT License for worry free distribution.

Quick start

This example uses the TCLAP 1.4 API and requires C++98 or later.

int main(int argc, char **argv) {
    try {
        TCLAP::CmdLine cmd("Print a greeting.", ' ', "1.0");
        TCLAP::ValueArg<std::string> name(
            "n", "name", "Name to greet", false, "world", "string", cmd);
        cmd.parse(argc, argv);
        std::cout << "Hello, " << name.getValue() << "!\n";
    } catch (const TCLAP::ArgException &e) {
        std::cerr << e.what() << '\n';
        return 1;
    }
    return 0;
}

Add the <tclap/CmdLine.h>, <iostream> and <string> headers and save as hello.cpp. With TCLAP headers on your include path, compile and run:

c++ -std=c++98 hello.cpp -o hello
./hello
Hello, world!
./hello --name Ada
Hello, Ada!

-n Ada also sets the name. Use --help to see all options. See the manual for more examples.

TCLAP is now a mature, stable, and feature rich package. Please don't let any apparent project inactivity discourage you from using the software!

Don't hesitate to send us your feedback!

Happy coding!

Choosing a version

Choose the version that matches your project's C++ and API requirements. Documentation: 1.2 and 1.6.