-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.cpp
34 lines (26 loc) · 941 Bytes
/
test3.cpp
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
#include "commandline.h"
#include "iostream"
using std::stringstream;
using std::cout;
int main ( int argc, char** argv ) {
int x=1, y=2; // declare two ints with default values
float pi=3.14; // declare float with default value
string str="default"; // declare string with default value
opts_t opts; // declare an opts_t instance and configure it.
opts
.addValue("x", "x value", &x) // add option for int x
.addValue("y", "y value", &y) // add option for int y
.addChoice( 1 ) // add choices for y (the last option)
.addChoice( 2 )
.addChoice( 3 )
.addValue("pi", "pi value", &pi)
.addValue("string", "string value", &str);
cout << "Usage:\n" << argv[0] << " [options]\n"
<< opts.usage() << "\n";
if ( ! opts.parse ( argc-1, argv+1 ) ) {
cout << "error parsing\n";
cout << opts.usage();
exit (1);
}
cout << "Dumping values:\n" << opts.dump();
};