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
5bf9b958f6
commit
11729b4dfe
@ -27,12 +27,20 @@ Argparse supports a variety of argument types including positional, optional, an
|
|||||||
Here's an example of a ***positional argument***:
|
Here's an example of a ***positional argument***:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
#include <argparse.hpp>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
argparse::ArgumentParser program("program name");
|
||||||
|
|
||||||
program.add_argument("square")
|
program.add_argument("square")
|
||||||
.help("display the square of a given integer")
|
.help("display the square of a given integer")
|
||||||
.action([](const std::string& value) { return pow(std::stoi(value), 2); });
|
.action([](const std::string& value) { return pow(std::stoi(value), 2); });
|
||||||
|
|
||||||
program.parse_args(argc, argv);
|
program.parse_args(argc, argv);
|
||||||
std::cout << program.get<double>("square") << std::endl;
|
std::cout << program.get<double>("square") << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And running the code:
|
And running the code:
|
||||||
|
Loading…
Reference in New Issue
Block a user