Advertisement
shchuko

Parser_use_example

Mar 22nd, 2020
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. int main(char **args) {
  2.     CArgsParser parser;
  3.  
  4.     COptionBuilder builder;
  5.  
  6.     const std::string FIN_OPTION_LONG_NAME = "fin";
  7.     const char FIN_OPTION_SHORT_NAME = 'i';
  8.  
  9.     builder.addShortName(FIN_OPTION_SHORT_NAME)
  10.     builder.addLongName(FIN_OPTION_LONG_NAME)  
  11.     parser.addOption(builder.build());
  12.     builder.reset();
  13.  
  14.     // Add more options here...
  15.  
  16.     try {
  17.         parser.parse(args);
  18.     } catch (std::exception& e) {
  19.         std::cerr << e.what() << std::endl;
  20.         return 1;
  21.     }
  22.  
  23.     std::string input_file_name = parser.getOptionValue(FIN_OPTION_LONG_NAME);
  24.     // OR
  25.     std::string input_file_name_2 = parser.getOptionValue(FIN_OPTION_SHORT_NAME);
  26.    
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement