VS2013下安装Boost库
本文讲解在VS2013中编译和配置Boost库。
1.下载并解压 Boost
到Boost的官网上下载http://www.boost.org/users/history/version\_1\_60\_0.html,这里选择的是最新版的boost
下载后解压到本地目录中,
以管理员身份执行boostrap.bat文件,执行完成之后会生成bjam.exe文件。
- 编译boost
在命令行中执行bjam.exe程序,此时会根据系统安装的msvc进行编译,
编译过程较长,需要等待一段时间,编译完成之后将会显示如下内容
- 在项目中使用boost
在VS2013 中新建一个VC++控制台程序的空项目,新建一个mian.cpp文件,在文件中输入以下内容:
#include <boost/lexical_cast.hpp>
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "Number: " << a << endl;
cout << "string: " << s0 << endl;
int c = 0;
try
{
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e)
{
cout << e.what() << endl;
}
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(in(std::cin),in(), std::cout<<(_1*3)<< " ");
system("pause");
return 0;
}
在项目属性中配置如下内容:
包含目录添加 G:\boost_1_60_0
库目录添加 G:\boost_1_60_0\stage\lib
执行程序,结果如下:
还没有评论,来说两句吧...