Boost logo

Boost Users :

From: Santosh Joseph (santoshjoseph73_at_[hidden])
Date: 2006-05-18 15:30:05


Code snippet is below...basically I have 2 options I
want to process "host,s" & "help,h".
I would like to process options like this:
for host: --host, -host, -s
for help: --help, -help, -h
Maybe I setup the opt_style variable wrong or is this
correct behavior?
I'm using boost 1.33.1

when i run the program:
> po.exe -host localhost -h
*** Command line processing error: ambiguous option h

thanks for any help,
-Santosh
======================================================
#include <iostream>
#include <string>
#include "boost/program_options.hpp"
using namespace std;
namespace po = boost::program_options;
int main(int, char *[])
{
   po::variables_map vm;
   po::options_description desc("Options");
   try
   {
      string strHostname;
      desc.add_options()
         ("host,s", po::value<string>(&strHostname),
"")
         ("help,h", "Show this help message");

      po::options_description cmdline_options;
      cmdline_options.add(desc);

      int opt_style =
(po::command_line_style::unix_style |
                      
po::command_line_style::allow_long_disguise |
                      
po::command_line_style::allow_slash_for_short);

      po::store(po::parse_command_line(argc, argv,
cmdline_options, opt_style), vm);
      po::notify(vm);

      cout << "host: " << strHostname << endl;
      if( vm.count("help") ) cout << "help is true" <<
endl;
   }
   catch(exception &e)
   {
      cout << endl << "*** Command line processing
error: " << e.what() << endl;
   }
   return 0;
}

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net