Update README.md

This commit is contained in:
Pranav Srinivas Kumar 2019-03-31 18:02:47 -04:00 committed by GitHub
parent c9d0c0098e
commit d0acbfdfb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<int>("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