Boost官方网站: http://www.boost.org/doc/libs/1_47_0/more/getting_started/windows.html
在线傻瓜安装 : http://www.boostpro.com/download/
VS中使用boost库(两步)
1 添加头文件的两种方法 :
- 将目录C:\Program Files\boost\boost_1_51\boost加入到项目中 ,在VS中右键项目名--属性--C/C++--常规添加包含路径 。然后就可以再main函数中使用#include “boost/regex.hpp”
- 将C:\Program Files\boost\boost_1_51\boost整个文件夹拷贝到 C:\Program Files\Microsoft Visual Studio 10.0\VC\include中,然后就可以再main函数中使用#include <boost/regex.hpp>
此时编译如下源文件:
- #include<iostream>
- #include <boost/regex.hpp>
- using namespace std;
- int main()
- {
- cout<<"Hello Boost !"<<endl;
- }
出现如下编译错误:
LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc100-mt-gd-1_51.lib'
2 添加lib和dll文件到工作目录 :
- 项目--属性--连接器--添加类库目录,将目录C:\Program Files\boost\boost_1_51\lib;加入其中
此时运行上面的源程序,结果如下:
若运行如下程序:
- #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;
- }
结果如下
完毕,所以使用专门的boost安装软件,只需要将两个目录加入到编译器中就可以使用boost库了,多方便啊!