In order to implement a tamperproof command line parsing, one usually has to write a significant amount of code. Using GetPot allows to shrink code fragments such as
... int i = 0; double v = 0; char* endptr = 0; ... if( i < argc ) { v = strtod(argv[i], &endptr); if( endptr == argv[i] ) // argv[i] was not a number v = 9.81; // set default value } ...to a single line
const double V = cl.get(i, 9.81);In fact, GetPot allows you to do much more sophisticated things in not more than one single program line. Additionally, GetPot provides a parser to handle input files such as 'example.pot':
... webpage = http://getpot.sourceforge.net/GetPot.html user = 'G. V. V. Bouche' # whitespace requires quotes clicks = 231 # [1/s] factor_x = 1.231 # [m/s^2] [vehicle] wheel-base = 2.65 # [m] initial-xyz = '100. 0.1 5.0' # [m] ...and read out its contents in the same way the command line was parsed. There are a few special things to know. In some aspects parsing input files differs from parsing the command line.