C++之Boost准标准库配置

下载安装

进入官网下载地址:https://www.boost.org/users/download/

本教程直接下载官方已编译库,不涉及源代码手动编译

点击官方编号好的链接,然后进入一个下载地址:https://sourceforge.net/projects/boost/files/boost-binaries/1.69.0/

下载完成后,安装,本人的安装路径为:D:\WindowsSoftware\Boost1.67.0

 创建一个项目测试代码

 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     return 0;
24 }

设置编译环境及链接

 配置 >> C/C++ >> 常规 >> 附加包含目录(此项为头文件目录,要保证能找到头文件,即D:\WindowsSoftware\Boost1.67.0中含有boost,而boost文件夹中为头文件)

 

点击链接器,附加库目录为编译时候产生的包含静态库或动态链接的文件夹,本文设置为编译时候设置的D:\WindowsSoftware\Boost1.67.0\lib64-msvc-14.1 

 

修改调试平台

 

解决编译时候产生的打不开文件问题(可省略)

错误如:(Win32): 已加载“C:\Windows\System32\ntdll.dll”。无法查找或打开 PDB 文件。
解决措施: 
点击【调试】—-【选项】—–右边勾上“【启用源服务器支持】”—-左边点“【符号】”—右边勾选“【微软符号服务器】”。 

调试运行

CTRL+F5 直接运行 
运行结果: 

 

猜你喜欢

转载自www.cnblogs.com/WindSun/p/10222849.html