boost库的安装和使用略记

转载:https://blog.csdn.net/chinawangfei/article/details/50351371

一、对于Windows平台,在VS2013中安装配置boost_1_58_0库(默认已安装vs2013)

1.到www.boost.org下载相应的代码包,我下载的是boost_1_58_0.tar.bz2

  1. 解压boost文件到本地目录(如G:\boost_1_58_0),可以发现解压后的文件中有一个bootstrap.bat文件。
    然后以管理员身份打开cmd窗口,转到bootstrap.bat文件所在路径,执行bootstrap.bat文件;
    3.上述命令执行完毕后,可以发现G:\boost_1_55_0下新生成了一个bjam.exe文件
    4.在命令窗口中输入语句:bjam.exe,执行bjam.exe
    此过程将默认根据系统已经安装好的编译工具(VS2008,2010,2012,2013)等编译相应的Lib文件、头文件等。(此步骤大概需要10分钟)
    5.添加boostest工程的包含目录(include头文件)和库目录(lib库文件)
    工程名->配置属性->c/c++->常规->附加包含目录,添加: G:\boost_1_58_0
    工程名->配置属性->链接器->常规->附加库目录,添加: G:\boost_1_58_0\stage\lib
    在工程中新建文件,内容为
#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;  
    }  
    return 0;  
}  

如果该文件可以编译和执行,则说明在VS2013中成功安装和配置boost_1_58_0库,否则安装和配置失败。
图片说明可以参考 http://jingyan.baidu.com/album/11c17a2c765763f446e39dc1.html?picindex=1

猜你喜欢

转载自blog.csdn.net/IT_BOY__/article/details/80191220