Boost logo

Boost Users :

From: Alexis H. Rivera-Rios (ahrivera_at_[hidden])
Date: 2005-03-06 14:51:56


Hi,

I was playing around with the boost::program_options
class...

According to the documentation the line:
desc.add_options()
        ("debug", po::value<std::string>()->implicit(),
        "enable debugging" );

enables me to do something like this:
myexec --debug

However, if I do that I get an assertion error. The
code
requires a string so this will work:
myexec --debug whatever

What am I doing wrong? Is it me or is it the library?

I'm using Visual C++ 2005 Express Beta, WinXP Pro
Service Pack2.

Thanks,
Alexis

Below my test program:

namespace po = boost::program_options;
int main (int argc, char **argv)
{
        po::options_description desc("Allowed ptions");

        desc.add_options()
                ("help", "produce help message")
                ("compression", po::value<int>(), "set compression
level")
                ("debug", po::value<std::string>()->implicit()
,"enable debugging" )
        ;

        po::variables_map vm;
        po::store(po::parse_command_line(argc, argv,
desc),vm);
        po::notify(vm);

        if (argc==1 || vm.count("help")) {
                std::cout << desc << "\n";
                return 1;
        }

        if (vm.count("compression"))
                std::cout << vm["compression"].as<int>() <<
std::endl;
        if (vm.count("debug"))
                std::cout << vm["debug"].as<std::string>() <<
std::endl;
        if (vm.count("log-file"))
                std::cout << vm["compression"].as<std::string>() <<
std::endl;

}

(By the way, the section Syntactic information of the
documentation is not accurate when it says I could do
this:
 desc.add_options()
        ("compression", "compression level",value<string>())
        ("verbose", "verbosity
level",value<string>()->implicit())
        ("email", "email to send
to",value<string>()->multitoken());

That doesn't compile. If I put the second string as
the last argument it works.)

Programming Tutorial:
In Python: To do this, do this
In Perl: To do this, do this or this or this or this...
In C: To do this, do this, but be careful
In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this

        
                
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/


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