boost::program_options 用法

https://blog.csdn.net/morning_color/article/details/50241987
代码流程

  • 构造option_description对象和variables_map对象
  • add_options()->向option_description对象添加选项
  • parse_command_line()->将命令行输入的参数解析出来
  • store()->将解析出的选项存储至variables_map中
  • notify()->通知variables_map去更新所有的外部变量
  • count()->检测某个选项是否被输入
  • operator[]->取出选项的值
#include "business_processer.h"
#include 
#include 

using namespace std;
using namespace boost;
using namespace boost::program_options;

int main(int argc,char* argv[])
{
    string config = "";
    string data_type = "";
    string version = "";
    try
    {
        options_description desc("Allowed options");
        desc.add_options()
                ("help,h", "produce help message")
                ("config,c", value()->default_value(""), "set config")
                ("data_type,t", value()->default_value(""), "set data type")
                ("version,v", value()->default_value(""), "set version");

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

        if (vm.count("help"))
        {
            cerr << desc << "\n";
            return 1;
        }
        if (vm.count("config"))
        {
            if (vm["config"].as().empty())
            {
                cerr<<"config is empty!!!"<();
                //cerr<<"config is: "<().empty())
            {
                cerr<<"data_type is empty!!!"<();
                //cerr<<"data_type is: "<().empty())
            {
                //cerr<<"version is empty!!!"<();
                //cerr<<"version is: "<

你可能感兴趣的:(boost::program_options 用法)