vs2010下 boost库的使用笔记(一)

下载boost_1_46_1库 http://www.boost.org/users/download/ (目前的版本为:1_55_0)
我把它解压缩到了E:/mylib/boost_1_46_1下面。
在vs上面  文件>新建 > 项目…
在左边的已 安装模板中选 Visual C++ > Win32.
然后再右边的面板中选 Win32控制台应用程序。
下面的名称输入  example 然后 确定 完成。
项目> example属性… >配置属性 >C/C++ >常规> 附加包含目录  输入Boost的目录路径
我这里是E:/mylib/boost_1_46_1
在  example属性… >配置属性 >C/C++> 预编译头 >预编译头 替换 使用(/Yu)不使用预编译头(第一次设置的时候,这里没有内容。我是保留#include "stdafx.h" 编译之后,再次设置的时候,发现了这个选项。如此设置后,我注释掉了#include "stdafx.h")
 复制代码到example.cpp文件
[cpp]  view plain copy
  1. #include <boost/lambda/lambda.hpp>  
  2. #include <iostream>  
  3. #include <iterator>  
  4. #include <algorithm>  
  5. int main()  
  6. {  
  7.     using namespace boost::lambda;  
  8.     typedef std::istream_iterator<int> in;  
  9.     std::for_each(  
  10.         in(std::cin), in(), std::cout << (_1 * 3) << " " );  
  11. }  
 
生成 >生成解决方案 
调试> 启动调试
控制台界面出现 
输入 1 2 3
输出 3 6 9

前面已经简单的使用了boost库,但是如果想要使用 

等,还是的编译一下,要不然就会出现如下的错误“LINK : fatal error LNK1104: 无法打开文件“libboost_regex-vc100-mt-gd-1_46_1.lib”

 

打开命令行窗口 

切换到 boost库的根目录。

我的是E:/mylib/boost_1_46_1

输入bootstrap

然后有几行输出

再输入./bjam

类库编译开始(这个真是个漫长的过程 ………………)

哎 等了 1个小时了 

还得等 

再编译一会儿吧

 

N久之后 编译好了

 

 

ln-NT stage/lib/libboost_unit_test_framework-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

ln-NT stage/lib/libboost_thread-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

ln-NT stage/lib/libboost_wave-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

...updated 786 targets...

 

The Boost C++ Libraries were successfully built!

 

The following directory should be added to compiler include paths:

 

    E:/mylib/boost_1_46_1

 

The following directory should be added to linker library paths:

 

    E:/mylib/boost_1_46_1/stage/lib

 

 

用如下代码替换上一次的那个example.cpp的内容

[cpp]  view plain copy
  1. #include <boost/regex.hpp>  
  2. #include <iostream>  
  3. #include <string>  
  4. int main()  
  5. {  
  6.     std::string line;  
  7.     boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );  
  8.     while (std::cin)  
  9.     {  
  10.         std::getline(std::cin, line);  
  11.         boost::smatch matches;  
  12.         if (boost::regex_match(line, matches, pat))  
  13.             std::cout << matches[2] << std::endl;  
  14.     }  
  15. }  
 

在工程中添加库引用

属性>连接器>常规 >  附加目录库 这里写入 E:/mylib/boost_1_46_1/stage/lib

编译

运行

输入

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
 
  
输出
Will Success Spoil Rock Hunter?
 
  
一个简单的正则表达式编译成功。
至此,boost库编译成功。
 
  

 

  1. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:/Program Files/boost/boost_1_46_1/lib/.
  2. From the Build menu, select Build Solution.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值