boost笔记(一) —— 开始

官网 http://www.boost.org/

参考网址: http://blog.csdn.net/callmeback/article/details/7715322

http://www.cnblogs.com/zhcncn/p/3950477.html

首先当然是下载解压了:D

源码: http://sourceforge.net/projects/boost/files/boost/1.60.0/

编译好的binary文件(包括lib和hpp) https://sourceforge.net/projects/boost/files/boost-binaries

一、目录结构

boost_1_60_0\ .................The “boost root directory”
   index.htm .........A copy of www.boost.org starts here
   boost\ .........................All Boost Header files
   lib\ .....................precompiled library binaries
   libs\ ............Tests, .cpps, docs, etc., by library
     index.html ........Library documentation starts here
     algorithm\
     any\
     array\
                     …more libraries…
   status\ .........................Boost-wide test suite
   tools\ ...........Utilities, e.g. Boost.Build, quickbook, bcp
   more\ ..........................Policy documents, etc.
   doc\ ...............A subset of all Boost library docs

二、Concept

  1.  Boost库分为2种:Header-Only Libraries和optional separately-compiled binaries。

    前者只需要include即可,后者需要编译

  2. bjam.exe和b2.exe作用是一样的,后者是升级版。

三、'Hello world'

Header-Only库只需要include即可,下面的例子是从官网摘抄

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

VS2010配置,其他类似:

      1) 附加包含目录(Additional Include Directories),解压后的boost根目录

      2) 取消预编译,VC++创建工程时,可以去掉预编译的勾选

165153_aOyk_2281329.png

编译运行后:

输入一个数字后,输出该数字*3

四、编译

可以从https://sourceforge.net/projects/boost/files/boost-binaries下载安装包(包含bjam和需要的lib)

1) 生成boost的自用的编译工具bjam.exe

首先打开“VS2010 开发人员命令提示”(其他版本类似),cd到boost根目录,输入bootstrap.bat(为嘛取bootstrap?刚开始还以为看错了……),会在boost根目录生成 b2.exe 、bjam.exe 、project-config.jam 、bootstrap.log四个文件。其中,b2.exe 、bjam.exe 这两个exe作用是一样的,bjam.exe 是老版本,b2是bjam的升级版本。

可以从https://sourceforge.net/projects/boost/files/boost-jam/直接下载已编译好的bjam

2) 使用bjam(或b2)来编译boost

详见http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html 5.2一节以及http://www.boost.org/build/doc/html/bbv2/overview/invocation.html

或者http://www.cnblogs.com/zhcncn/p/3950477.html

b2 --toolset=msvc-10.0 --build-type=complete

编译成功后,会出现如下图所示的提示(include和lib目录)

170434_N0Cd_2281329.png

五、'Hello world'升级版

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

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

1)附加包含目录 boost根目录

2)附加库目录 boost根目录/stage/lib

3)取消预编译

编译生成后:

输入Subject: (Re: )abcd.efg

输出(Re: )abcd.efg

转载于:https://my.oschina.net/shanlilaideyu/blog/625461

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值