如何将BOOST库集成到VS2019中去使用呢?
Boost库使用前的操作
1、先去官网下载boost压缩包
Boost 官网

2、解压后,双击运行booststrap.bat文件
运行完后,会生成一个b2.exe文件
3、然后在boost文件夹下启动cmd,执行 “.\b2.exe toolset=gcc”

编译时间和机器性能有关,执行编译过后,会在stage文件夹下生成lib文件夹,里面就是我们要用到的lib库。(编译时间大约有15-20分钟)
4、生成的stage文件夹下的lib文件夹,里面就是我们要用到的lib库
将这个Boost库放置到一个项目中去使用(也可以将其放置到环境变量中)
1、未放置之前的样子
2、放置库文件的详细步骤
右键工程 -> 选择属性 -> 选择VC++目录 -> 包含目录,添加 D:\cppsoft\boost_1_81_0; 选择VC++目录 -->库目录,添加 D:\cppsoft\boost_1_81_0\stage\lib;

3、测试验证
// 004.cpp: 定义控制台应用程序的入口点。
#include<iostream>
using namespace std;//包含头文件
#include<boost/lexical_cast.hpp>int main()
{/*// 字符串转整数 a to iint a = atoi("123");cout << a << endl;// 整数转字符串 i to achar b[64] = {0};itoa(16, b, 2);cout << b << endl;// 字符串转浮点数 a to fdouble c = atof("1.23456");cout << c << endl;// 浮点数转字符串 gcvtchar d[64] = { 0 };gcvt(1.23456, 4, d);//四舍五入cout << d<< endl;*/using boost::lexical_cast;// 声明,省略boost名字空间前缀using boost::bad_lexical_cast;try{//字符串转整型//int a = lexical_cast<int>("123");int a = lexical_cast<int>("123efd", 3);cout << a << endl;//字符串 转 浮点型float b = lexical_cast<float>("1.23456");cout << b << endl;//浮点数转为字符串string c = lexical_cast<string>("1.23456");cout << c << endl;//浮点数转为字符串string d = lexical_cast<string>("666");cout << d << endl;}//catch (const std::exception& e)catch (const bad_lexical_cast& e){cout << e.what() << endl;}return 0;
}
在使用中,一个比较蛋疼的报错信息
1、我Boost库使用的是x64
2、而我把这个步骤完美的添加后,还是会报错
右键工程 -> 选择属性 -> 选择VC++目录 -> 包含目录,添加 D:\cppsoft\boost_1_81_0; 选择VC++目录 -->库目录,添加 D:\cppsoft\boost_1_81_0\stage\lib;
3、提示的信息如下

4、最后发现,是我的配置环境不太对,我应该用x64,而不是x86
换成x64就好了

EDN




