ArgumentParse

class ArgumentParse

Parse command line arguments given to main() in C++.

Public Functions

ArgumentParse(const char *header, std::vector<std::vector<std::string>> options = std::vector<std::vector<std::string>>())

Construct with documentation to print when “-h” option is given.

Parameters
  • options: Add documention and default value for options. For each option, the first value is the option itself. The second is the documentation string. And the third (optional) is the default value.

std::string parse(int argc, char **argv)

Parse the c-style input arguments. If “-h” option is given, print the documentation. Otherwise, return the arguments as a string.

ArgumentParse(int argc, char **argv)

Construct directly from the c-style input arguments.

const std::vector<std::string> &args() const

Return the input arguments.

const std::string str()

Return the input arguments as a string.

bool option_given(const std::string &option) const

Return true if option was given.

const std::string get(const std::string &option) const

Return option.

double get_double(const std::string &option) const

Same as get(), but return option as a double.

int get_int(const std::string &option) const

Same as get(), but return option as an int.