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,
#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");
      string strHostname;
         ("host,s", po::value<string>(&strHostname),
         ("help,h", "Show this help message");

      po::options_description cmdline_options;

      int opt_style =
(po::command_line_style::unix_style |
po::command_line_style::allow_long_disguise |

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

      cout << "host: " << strHostname << endl;
      if( vm.count("help") ) cout << "help is true" <<
   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

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at