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

    xiaoxiao2021-04-15  35

    &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 程序结果

     

    转载请注明原文地址: https://ju.6miu.com/read-671558.html

    最新回复(0)