参考网址: 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
Boost库分为2种:Header-Only Libraries和optional separately-compiled binaries。
前者只需要include即可,后者需要编译
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++创建工程时,可以去掉预编译的勾选
编译运行后:
输入一个数字后,输出该数字*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目录)
五、'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