-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount3.cpp
More file actions
32 lines (31 loc) · 996 Bytes
/
count3.cpp
File metadata and controls
32 lines (31 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "argparse.hpp"
#include <iostream>
auto main(int argc, char * argv[]) -> int
{
try
{
auto parser = argparse::ArgumentParser();
parser.add_argument("square").help("display a square of a given number").type<int>();
parser.add_argument("-v", "--verbosity").help("increase output verbosity").action(argparse::count);
auto parsed = parser.parse_args(argc, argv);
auto value = parsed.get_value<int>("square");
auto answer = value * value;
auto verbosity = parsed.get_value<int>("verbosity");
if (verbosity >= 2)
{
std::cout << "the square of " << value << " equals " << answer << '\n';
}
else if (verbosity >= 1)
{
std::cout << value << "^2 == " << answer << '\n';
}
else
{
std::cout << answer << '\n';
}
}
catch (argparse::type_error const & e)
{
std::cout << "error: " << e.what() << '\n';
}
}