【boost学习笔记】命令行解析库(program_options)
来源:互联网 发布:java进阶路线 书籍 编辑:程序博客网 时间:2024/05/16 01:01
代码:
// Copyright Vladimir Prus 2002-2004.// Distributed under the Boost Software License, Version 1.0.// (See accompanying file LICENSE_1_0.txt// or copy at http://www.boost.org/LICENSE_1_0.txt)/* The simplest usage of the library. */#include <boost/program_options.hpp>namespace po = boost::program_options;#include <iostream>#include <iterator>using namespace std;int main(int ac, char* av[]){ try { po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("compression", po::value<double>(), "set compression level")("include-path,I", po::value<std::string>(), "set path")("debugflag,D", po::value<bool>(), "set file") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) { cout << desc << "\n"; //return 0; } if (vm.count("compression")) { cout << "Compression level was set to " << vm["compression"].as<double>() << ".\n"; } else { cout << "Compression level was not set.\n"; }if (vm.count("include-path")) {cout << "include-path are : " << vm["include-path"].as<std::string>() << ".\n";} else {cout << "include-path was not set.\n";}if (vm.count("debugflag")) {cout << "debugflag are : " << vm["debugflag"].as<bool>() << ".\n";} else {cout << "debugflag was not set.\n";} } catch(exception& e) { cerr << "error: " << e.what() << "\n"; return 1; } catch(...) { cerr << "Exception of unknown type!\n"; } return 0;}
上面程序加上如下参数运行:
testDemo --help --compression 12 -I ssssss -D true
结果:
Allowed options:
-h [ --help ] produce help message
--compression arg set compression level
-I [ --include-path ] arg set path
-D [ --debugflag ] arg set file
Compression level was set to 12.
include-path are : ssssss.
debugflag are : 1.
0 0
- 【boost学习笔记】命令行解析库(program_options)
- boost学习之命令行参数解析库program_options
- boost::program_options 解析命令行参数
- boost.Program_options 命令行参数解析
- boost -- program_options 学习笔记
- boost之program_options库,解析命令行参数、读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- boost库之program_options
- Boost库之Program_options
- boost::program_options 命令行选项 子命令
- boost:库program_options--第一篇
- boost program_options
- boost.program_options
- Boost.Program_options
- boost -- program_options
- boost::program_options
- LeetCode_6_ZigZag Conversion(Java)
- 弹窗 解决游览器不兼容问题
- 字符串最后一个单词的长度 C语言版本
- 最大公约数,最小公倍数
- Android之史上最全最简单最有用的第三方开源库收集整理
- 【boost学习笔记】命令行解析库(program_options)
- Centos 7 安装X-windows和VNC步骤
- 数字三角
- cannot change version of project facet Dynamic web module to 2.5
- oracle tnsping 慢的问题
- 欢迎使用CSDN-markdown编辑器
- Map端的调优属性
- 设计模式(9)--观察者模式
- iOS 屏幕根据感应自动旋转