From d0acbfdfb6f844d65e2a21c7eafb8e710e60cf31 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sun, 31 Mar 2019 18:02:47 -0400 Subject: [PATCH] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 4d824a2..365c165 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,28 @@ Here's what's happening: ### Combining Positional and Optional Arguments +```cpp +argparse::ArgumentParser program("test"); + +program.add_argument("square") + .help("display the square of a given number") + .action([](const std::string& value) { return std::stoi(value); }); + +program.add_argument("--verbose") + .default_value(false) + .implicit_value(true); + +program.parse_args({ "./main", "4", "--verbose" }); + +int input = program.get("square"); + +if (program["--verbose"] == true) { + std::cout << "The square of " << input << " is " << (input * input) << std::endl; +} +else { + std::cout << (input * input) << std::endl; +} +``` ### List of Arguments