sophia_hxw

人生有三恨,一恨鲫鱼有刺,二恨海棠无香,三恨红楼未完!----------张爱玲
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

VS2013中BOOST库的环境配置与使用

Posted on 2016-04-15 11:28  sophia_hxw  阅读(209)  评论(0编辑  收藏  举报

&1 安装Boost

文件下载:链接:http://pan.baidu.com/s/1kUKaOFP 密码:auf2

解压之后放到你想安装的文件夹内,我的是在C:\Program Files\boost\boost_1_60_0中。

 

&2 运行bootstrap.bat文件

以管理员权限运行cmd,切换到boost目录,运行bootstrap.bat文件,结果如下所示:

 

&3 文件夹内会生成一个bjam.exe文件,下一步就是运行它

结果如下图所示:

 

&4 配置VS2013

  • 项目右键单击->属性->C/C++->附加包含目录

    配置的目录为:C:\Program Files\boost\boost_1_60_0

  • 项目键单击->属性->链接器->附加库目录

    配置目录:C:\Program Files\boost\boost_1_60_0\libs

 

&5 测试代码

 1 #include <boost/lexical_cast.hpp> 
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8 using boost::lexical_cast;
 9 int a = lexical_cast<int>("123");
10 double b = lexical_cast<double>("123.0123456789");
11 string s0 = lexical_cast<string>(a);
12 string s1 = lexical_cast<string>(b);
13 cout << "number: " << a << " " << b << endl;
14 cout << "string: " << s0 << " " << s1 << endl;
15 int c = 0;
16 try{
17 c = lexical_cast<int>("abcd");
18 }
19 catch (boost::bad_lexical_cast& e){
20 cout << e.what() << endl;
21 }
22 
23 system("Pause");
24 return 0;
25 }
boost测试

 

 

&6 程序结果