Boost练习程序(program_options)

#include <iostream>
#include <string>
#include <boost/program_options.hpp>

int main(int argc,char **argv)
{
    namespace po = boost::program_options;

    po::option_description desc("allowed options");

    desc.add_options()
        ("help,h",        "help message")
        ("version,v",    "display verison")
        ;

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

    if (vm.count("help"))
    {
        std::cout<<desc<<std::endl;
        return 0;
    }

    if (vm.count("version"))
    {
        std::cout<<"version 0.0.1"<<std::endl;
        return 0;
    }

    std::cout<<"exec program"<<std::endl;
    return 0;

}
原文地址:https://www.cnblogs.com/tiandsp/p/2582198.html