一、安装boost库

sudo apt-get install libboost-dev
aptitude search boost

二、编写测试代码

 #include <iostream>
#include <string>
#include <boost/program_options.hpp> namespace bpo = boost::program_options;
using namespace std; int main(int argc, char const *argv[])
{
//步骤1:构造选项描述器
//选项描述起,其参数为该描述器名字
bpo::options_description opts("all options");
//选项存储器,继承自map容器
bpo::variables_map vm; //步骤2:为选项描述器增加选项
//其参数依次为:key,value的类型,该选项描述
opts.add_options()
("filename", bpo::value<std::string>(), "the file name which want to be found")
("help", "this is a program to find a specified file"); //步骤3:先对命令行输入的参数做解析,而后将其存入选项存储器
//如果输入了未定义的选项,程序会抛出异常,所以对解析代码要用try-catch块包围
try {
//parse_command_line()对输入的选项做解析
//store()将解析后的结果存入选项存储器
bpo::store(bpo::parse_command_line(argc, argv, opts), vm);
} catch(...) {
std::cout<<"Input option not exsited."<<std::endl;
return ;
} //步骤4:参数解析完毕,处理实际信息
//count()检测该选项是否被输入
if(vm.count("help")) { //若参数中有help选项
//options_description对象支持流输出,会自动打印所有的选项信息
std::cout<<opts<<std::endl;
}
if(vm.count("filename")) {
//variables_map(选项存储器)是std::map的派生类,可以像关联容器一样使用,
//通过operator[]来取出其中的元素,但其内部的元素类型value_type是boost::any,
//用来存储不确定类型的参数值,必须通过模版成员函数as<type>()做类型转换后,
//才能获取其具体值
std::cout<<"find"<<vm["filename"].as<std::string>()<<std::endl;
}
if(vm.empty()) {
std::cout<<"no options found"<<std::endl;
}
return ;
}

编译时要加上库名字:

g++ -o s main.cpp -lboost_program_options

使用效果:

pi@raspberrypi:~/chen_DIR/weihua/myoptions $ ./s --help
all options:
--filename arg the file name which want to be found
--help this is a program to find a specified file pi@raspberrypi:~/chen_DIR/weihua/myoptions $ ./s --filename s
finds

树莓派上安装boost库的更多相关文章

  1. C++: Mac上安装Boost库并使用CLion开发

    1.下载安装Boost库 官网下载最新版本1.65.0:http://www.boost.org/users/history/version_1_65_0.html 选择UNIX版本: 下载后解压cd ...

  2. 在Ubuntu上安装boost库[转]

    在编译kenlm的时候需要安装boost,去官网下载boost安装包,然后按照以下步骤安装. boost官网 -----------------以下内容,网上转载------------------- ...

  3. ubuntu上安装boost库

    只需一条命令: sudo apt install libboost-dev

  4. linux下编译安装boost库

    linux下编译安装boost库 linux下编译安装boost库 1.下载并解压boost 1.58 源代码 下载 解压 2.运行bootstrap.sh 3.使用b2进行构建 构建成功的提示 4. ...

  5. Centos 安装boost库

    1.在http://www.boost.org/下载boost安装包boost_1_65_1.tar.gz 2.在Centos上解压tar -zxvf  boost_1_65_1.tar.gz后,cd ...

  6. 在树莓派上安装Theano

    “查遍全网都没人成功在树莓派安装Theano,这是什么样的感觉?” ——写在开头 在这里必须先说一下,由于安装过程中的坑太多了,遇到的问题层出不穷,所以我这里只能记录我安装过程中的印象深刻的问题,如果 ...

  7. ubuntu 下安装boost库

    ubuntu下安装boost库,,在网上试了一些其他人推荐的libboost-dev 但是会缺少,编译程序会报错: /usr/bin/ld: cannot find -lboost_serializa ...

  8. VS2010下安装boost库

    在我们的C++项目中安装boost库,下面以VS2010版本作为例子,其它版本的设置也差不多. 一.编译生成boost库 1.下载最新的boost(本人下载的是boost_1_56_0).boost官 ...

  9. windows下编译和安装boost库

    boost是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库. 获取方式 boost提供源码形式的安装包,可以从boost官方网站下载,目前最新版本是1.59.0. 本机上正好有boos ...

随机推荐

  1. HttpClient之HttpContext使用

    Multiple request sequences that represent a logically related session should be executed with the sa ...

  2. kNN#约会网站预测数据

    #约会网站预测数据 def classifyPersion(): resultList = ['not at all','in small doses','in large doses'] #inpu ...

  3. AcWing 257. 关押罪犯 (并查集)打卡

    题目:https://www.acwing.com/problem/content/description/259/ 题意:有两个监狱,监狱里面有很多犯人,现在有很多对冲突,还有个冲突值,现在问我们怎 ...

  4. Ant Design Pro (中后台系统)教程

    一.概念:https://pro.ant.design/docs/getting-started-cn(官方网站) 1.Ant Design Pro 是什么:  https://www.cnblogs ...

  5. ASP.NET免费发送邮件|

    因为之前有做过邮件发送的项目,最近也看一些朋友问起这个的做法,现在拿来给大家查看下.因为那时候是公司的服务器配置的.所以后来自己便在网上找到了一个可以任何个人都是可以使用的邮件发送.小弟新手,高手看到 ...

  6. 提高redis cluster集群的安全性,增加密码验证

    节点设置密码 1.修改配置文件 在配置文件里面增加密码选项,一定要加上masterauth,不然Redirected的时候会失败. masterauth redispassword requirepa ...

  7. 系统安装2---BIOS设置

    对于新的电脑通过U盘安装Windows系统,我们第一步绝对是修改BIOS设置.在这里面我们要修改几项比较重要的选项.如下介绍: 修改第一启动项:目的就是让电脑的第一启动项变为U盘启动. 调节引导方式: ...

  8. Oracle基础数据类型与运算符

    Oracle基础数据类型: 1. 字符型:字符串 char(最大2000), nchar(最大1000, 支持                           Unicode)--->固定长 ...

  9. 同一台机器上有多个Python版本?

    有关Python网站上的官方文档,如何在Linux上的同一台机器上安装和运行多个版本的Python? 我可以找到大量的博客帖子和答案,但我想知道是否有“标准”官方方式这样做? 或者这完全取决于操作系统 ...

  10. [Fw] assembly code in gas syntax

    Address operand syntax There are up to 4 parameters of an address operand that are presented in the ...