Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一。安装过程如下:
1. 从http://www.boost.org/上找最新的boost版本下载。我选用的是最新版本Version 1.58.0。
2. 进入下载页面,选择windows boost_1_58_0.zip。
3. 下载好后解压到D盘。比如我的为例:D:\boost_1_58_0。所在盘符剩余容量应大于6GB。
4. 打开程序菜单,选择Visual Studio Tools里面的 Visual Studio 命令提示(2010)打开控制台,并进入目录(即解压目录):cd d:\boost_1_58_0\boost_1_58_0。
5. 输入如下命令bootstrap.bat。
6.等待一段时间,会自动生成 bjam.exe 和 b2.exe 。然后输入bjam --toolset=msvc-10.0 --build-type=complete 执行编译,编译时间较长,耐心等待。大概一两个小时左右。
7. 如图显示为编译完成,至此安装结束。下面为具体测试。
测试:
1. 在VS中新建一个工程,右击点属性,配置属性,VC++目录。在“包含目录”中附加包含目录为:d:\boost_1_58_0\boost_1_58_0;在“库目录”中附加库目录为:d:\boost_1_58_0\boost_1_58_0\stage\lib。
2. 编写代码测试:
注:如果编写的测试代码出现类似错误”无法打开包括文件:“boost/regex.hpp”: No such file or directory” 说明附件包含目录出现错误,这时要纠正包含目录。
如果在下还有incude目录,我们只需包含includes目录就加载了相关头文件,如果没有,如上加载总目录,让编译器自己找。
测试代码如下:
#include<iostream>
#include <boost/regex.hpp>
using namespace std;
int main()
{
// 3 digits, a word, any character, 2 digits or "N/A",
// a space, then the first word again
boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");
std::string correct="123Hello N/A Hello";
std::string incorrect="123Hello 12 hello";
assert(boost::regex_match(correct,reg)==true);
assert(boost::regex_match(incorrect,reg)==false);
cout<<"Hello Boost !"<<endl;
system("pause");
}
如果测试结果如下,说明配置成功!