demo/arg_parser_demo.cc
changeset 865 d48d79b11f5b
parent 440 88ed40ad0d4f
child 877 141f9c0db4a3
equal deleted inserted replaced
7:1873c299f020 8:f3483164ed5e
    63   ap.onlyOneGroup("gr");
    63   ap.onlyOneGroup("gr");
    64   // Add non-parsed arguments (e.g. input files)
    64   // Add non-parsed arguments (e.g. input files)
    65   ap.other("infile", "The input file.")
    65   ap.other("infile", "The input file.")
    66     .other("...");
    66     .other("...");
    67 
    67 
       
    68   // Throw an exception when problems occurs. The default behavior is to
       
    69   // exit(1) on these cases, but this makes Valgrind falsely warn
       
    70   // about memory leaks.
       
    71   ap.throwOnProblems();
       
    72   
    68   // Perform the parsing process
    73   // Perform the parsing process
    69   // (in case of any error it terminates the program)
    74   // (in case of any error it terminates the program)
    70   ap.parse();
    75   // The try {} construct is necessary only if the ap.trowOnProblems()
       
    76   // setting is in use.
       
    77   try {
       
    78     ap.parse();
       
    79   } catch (ArgParserException &) { return 1; }
    71 
    80 
    72   // Check each option if it has been given and print its value
    81   // Check each option if it has been given and print its value
    73   std::cout << "Parameters of '" << ap.commandName() << "':\n";
    82   std::cout << "Parameters of '" << ap.commandName() << "':\n";
    74 
    83 
    75   std::cout << "  Value of -n: " << i << std::endl;
    84   std::cout << "  Value of -n: " << i << std::endl;