VS2010中使用Boost库的方法(超级简单)

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>

此时编译如下源文件:

[cpp]  view plain copy
  1. #include<iostream>  
  2. #include <boost/regex.hpp>  
  3. using namespace std;  
  4.   
  5. int main()  
  6. {  
  7.     cout<<"Hello Boost !"<<endl;  
  8. }  

出现如下编译错误:

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;加入其中

此时运行上面的源程序,结果如下:

若运行如下程序:

[cpp]  view plain copy
  1. #include<iostream>  
  2. #include <boost/regex.hpp>  
  3. using namespace std;  
  4.   
  5. int main()  
  6. {  
  7.     // 3 digits, a word, any character, 2 digits or "N/A",   
  8.     // a space, then the first word again  
  9.     boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");  
  10.   
  11.     std::string correct="123Hello N/A Hello";  
  12.     std::string incorrect="123Hello 12 hello";  
  13.   
  14.     assert(boost::regex_match(correct,reg)==true);  
  15.     assert(boost::regex_match(incorrect,reg)==false);  
  16.     cout<<"Hello Boost !"<<endl;  
  17. }  


结果如下

完毕,所以使用专门的boost安装软件,只需要将两个目录加入到编译器中就可以使用boost库了,多方便啊!


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值