c_cpp 使用boost库的cpp程序的参数解析器。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 使用boost库的cpp程序的参数解析器。相关的知识,希望对你有一定的参考价值。

// arguments parser
  po::options_description desc("Usage");
  desc.add_options()
      ("help", "produce help message")
      ("dataset_root", po::value<std::string>(), "dataset root folder")
      ("dataset_id", po::value<std::string>(), "dataset id used for test.")
      ("subject_id", po::value<std::string>(), "subject id (video name) used "
          "for test.")
      ("output_root", po::value<std::string>(), "output root folder");

  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 1;
  }

  // check the dataset_id argument
  std::string dataset_id;
  if (vm.count("dataset_id")) {
    dataset_id = vm["dataset_id"].as<std::string>();
  } else {
    std::cout << "Please specify the dataset ID with --dataset_id"
              << std::endl;
    std::cout << desc << std::endl;
    return -1;
  }
  std::cout << "Use dataset " << dataset_id << " for testing." << std::endl;

  // check the subject_id argument
  std::string subject_id;
  if (vm.count("dataset_root")) {
    subject_id = vm["subject_id"].as<std::string>();
  } else {
    std::cout << "Please specify the subject ID path with --subject_id"
              << std::endl;
    std::cout << desc << std::endl;
    return -1;
  }
  std::cout << "Use subject ID: " << subject_id << " for testing." << std::endl;

  // check the  dataset_root argument
  std::string dataset_root;
  if (vm.count("dataset_root")) {
    dataset_root = vm["dataset_root"].as<std::string>();
  } else {
    std::cout << "Please specify the dataset root path with --dataset_root"
              << std::endl;
    std::cout << desc << std::endl;
    return -1;
  }
  std::cout << "Dataset root path: " << dataset_root << std::endl;

  // check the input output_root argument
  std::string output_root;
  if (vm.count("output_root")) {
    output_root = vm["output_root"].as<std::string>();
  } else {
    std::cout << "Please specify the output root path with --output_root"
              << std::endl;
    std::cout << desc << std::endl;
    return -1;
  }
  std::cout << "Output root path: " << output_root << std::endl;

以上是关于c_cpp 使用boost库的cpp程序的参数解析器。的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp NMEA格式解析

c_cpp 上行报文解析

c_cpp MFC解析命令行

c_cpp OpenCV构建信息解析器

c_cpp 将方程式解析成矩阵

c_cpp 一种解析调用pantry解析的新方法,可用于解析非嵌套语言。