EXAMPLE

Using the library is relatively easy - you need to construct your arguments, your command-line, and your argument iterator. Then all that is left to do is call the parse member function of your object. The following is a simple example: #include <stdlib.h> #include <iostream.h> #include <cmdargs.h> int main(int argc, char * argv[]) {
      // Declare arguments
   CmdArgInt count('c', "count", "number",
                       "number of copies to print.");

   CmdArgBool xflag('x', "xmode",
                       "turn on 'x'-mode.");

   CmdArgChar fdsep('s', "separator", "char",
                       "field-separator to use.");

   CmdArgStr input("input-file",
                       "input file to read.");

   CmdArgStrList output("[output-file ]",
                        "where to print output.");
      // Declare the command and the argument-iterator
   CmdLine cmd(*argv,
                   &count, &xflag, &fdsep,
                   &input, &output, NULL);

   CmdArgvIter arg_iter(--argc, ++argv);
      // Initialize arguments to appropriate default values.
   count = 1;
   xflag = 0;
   fdsep = ',';
      // Parse arguments
   cmd.parse(arg_iter);
      // Print arguments
   cout << "count=" << count << endl ;
   cout << "xflag=" << (xflag ? "ON" : "OFF") << endl ;
   cout << "fdsep='" << (char) fdsep << "'" << endl ;
   cout << "input=\"" << input << "\"" << endl ;

   for (int i = 0 ; i < output.count() ; i++) {
      cout << "output[" << i << "]=" << output[i] << endl ;
   }
   return 0; } The Unix command-line syntax for the above program would be as follows: progname [-c number] [-x] [-s char] input-file [output-file ] The Unix command-line syntax using long-options (keywords) for the above program would be as follows: progname [--count number] [--xmode] [--separator char]
         input-file [output-file ]