mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Update README.md
This commit is contained in:
parent
c9d0c0098e
commit
d0acbfdfb6
22
README.md
22
README.md
@ -77,6 +77,28 @@ Here's what's happening:
|
|||||||
|
|
||||||
### Combining Positional and Optional Arguments
|
### 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
|
### List of Arguments
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user