Skip to content

jemarq04/cpp-argparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPP Argument Parser (argparse)

A command-line argument parser for C++11 (and later) that mimics python's argparse. This file will focus on how the implementation in C++ differs from python.

Using cpp-argparse

To get started, move the argparse.h file into your working area and add #include "argparse.h" at the top of your C++ script. Now you can access all of the classes and enums located in the argparse namespace. (If you'd prefer argparse.h in a different location, just be sure to include its directory in your compilation.)

We need to access the command-line arguments to be able to parse them, so a template for a simple script would look something like the following snippet.

#include <iostream>
#include "argparse.h"

int main(int nargs, char** argv){

  //Here is where our argument parsing would take place.

  return 0;
}

From here on, we will assume that the number of command-line arguments is nargs and the array of c-strings is argv.

ArgumentParser Class

First, we need to create an argument parser instance. This can be created simply using the ArgumentParser class's only constructor. (Here we assume the appropriate code surrounding this statement.)

auto parser = argparse::ArgumentParser(nargs, argv);

(Documentation WIP. More will be added soon.)

About

A command-line argument parser for C++ that mimics python's argparse.

Resources

Stars

Watchers

Forks