Window 平台下安装Boost

Window 平台下安装Boost

最近因为要用C++做后台,所以就弄了一个Boost库,在网上看了很多的安装教程。可是,这些老司机总是只把你带到终点,就不告许你怎么弄的,或是断断续续的,所以就像写一篇完整一点的安装教程。

下载

首先,可以在boost网站上,下载一个boost的windows版本的压缩包。链接地址为:http://www.boost.org/users/download/
点击到download页面之后,选择.7z版本的。

运行脚本

我使用的是vs2013 x64本机工具命令提示,进行运行脚本。这个是在安装vs2013的时候附带的工具,如果找不到,可以去vs2013的安装路径找一下。

直接敲上bootstrap.bat就会在根目录生成bjam.exe

编译

64位机的编译命令

bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel
--without-math --without-mpi --without-serialization --without-wave --without-test --without
-program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x64" link=
static runtime-link=shared threading=multi debug release address-model=64

其中出现路径的是我设的值,你们请随意。

如果出现了bin,说明编译成功了。

配置项目的参数

右键项目,然后选中属性。

附加包含目录

这里写图片描述

附加库目录

这里写图片描述

测试

#include <boost/lexical_cast.hpp>       

#include <iostream>       

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 << "  " << b << endl;

    cout << "string: " << s0 << "  " << s1 << endl;

    int c = 0;

    try{

        c = lexical_cast<int>("abcd");

    }

    catch (boost::bad_lexical_cast& e){

        cout << e.what() << endl;

    }
    system("pause");
    return 0;

}

输出:

number: 123  123.012
string: 123  123.0123456789
bad lexical cast: source type value could not be interpreted as target
请按任意键继续. . .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值