Boost logo

Boost Users :

From: Jeffrey Schmidt (jschmidt_at_[hidden])
Date: 2007-06-22 09:06:10


(apologies if this comes through multiple times, I'm having subscription issues)

I'm a novice Boost user attempting to use program_options. As far as I
can tell from the docs and sample code, this should work (only
relevant code included):

       po::options_description desc("Allowed options");
       desc.add_options()
               ("client", po::value<string>(), "set client name")
               ("test", "tool test mode, dump command line options only")
       ;

       po::variables_map vm;
       po::store(po::parse_command_line(ac, av, desc), vm);
       po::notify(vm);

       if (vm.count("test")) {
               if (vm.count("client")) cout << "client set to " <<
vm["client"].as<string>() << "\n";
               else cout << "client not set\n";
       }

However, when I run with "--client testclient --test", the as<string>
call generates a bad_any_cast exception. What am I missing or
misunderstanding?

-- 
Jeffrey Schmidt, senior software architect
MultiAd(r) Creator and Creator Server
jschmidt_at_[hidden]

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