forked from p-ranav/argparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegative_numbers.cpp
More file actions
34 lines (27 loc) · 817 Bytes
/
negative_numbers.cpp
File metadata and controls
34 lines (27 loc) · 817 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
33
34
// SPDX-License-Identifier: MIT
#include <argparse/argparse.hpp>
int main(int argc, char *argv[]) {
argparse::ArgumentParser program("test");
program.add_argument("integer").help("Input number").scan<'i', int>();
program.add_argument("floats")
.help("Vector of floats")
.nargs(4)
.scan<'g', float>();
try {
program.parse_args(argc, argv);
} catch (const std::exception &err) {
std::cerr << err.what() << std::endl;
std::cerr << program;
return 1;
}
if (program.is_used("integer")) {
std::cout << "Integer : " << program.get<int>("integer") << "\n";
}
if (program.is_used("floats")) {
std::cout << "Floats : ";
for (const auto &f : program.get<std::vector<float>>("floats")) {
std::cout << f << " ";
}
std::cout << std::endl;
}
}