mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Update README.md
This commit is contained in:
parent
5bf9b958f6
commit
11729b4dfe
18
README.md
18
README.md
@ -27,12 +27,20 @@ Argparse supports a variety of argument types including positional, optional, an
|
||||
Here's an example of a ***positional argument***:
|
||||
|
||||
```cpp
|
||||
program.add_argument("square")
|
||||
.help("display the square of a given integer")
|
||||
.action([](const std::string& value) { return pow(std::stoi(value), 2); });
|
||||
#include <argparse.hpp>
|
||||
|
||||
program.parse_args(argc, argv);
|
||||
std::cout << program.get<double>("square") << std::endl;
|
||||
int main(int argc, char *argv[]) {
|
||||
argparse::ArgumentParser program("program name");
|
||||
|
||||
program.add_argument("square")
|
||||
.help("display the square of a given integer")
|
||||
.action([](const std::string& value) { return pow(std::stoi(value), 2); });
|
||||
|
||||
program.parse_args(argc, argv);
|
||||
std::cout << program.get<double>("square") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
And running the code:
|
||||
|
Loading…
Reference in New Issue
Block a user