如何将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、测试验证

c++ 复制代码
// 004.cpp: 定义控制台应用程序的入口点。
#include<iostream>
using namespace  std;

//包含头文件
#include<boost/lexical_cast.hpp>

int main()
{
	/*
	// 字符串转整数 a to i
	int  a = atoi("123");
	cout << a << endl;

	// 整数转字符串 i to a
	char b[64] = {0};
	itoa(16, b, 2);
	cout << b << endl;

	// 字符串转浮点数 a to f
	double  c = atof("1.23456");
	cout << c << endl;

	// 浮点数转字符串 gcvt
	char 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

相关推荐
千里马-horse8 天前
Boost.Iostreams 简介
开发语言·c++·boost
云雾J视界9 天前
开关电源拓扑工程宝典:从原理到实战的深度设计指南
gan·boost·开关电源·1024程序员节·buck·拓扑电路
creator_Li13 天前
socket
boost
rosemary51223 天前
libboost_system-mt-x64.so.1.76.0 和libboost_system-mt-d-x64.so.1.76.0 区别
boost
xiecoding.cn1 个月前
Boost下载安装教程(附安装包,图文并茂)
boost·boost下载·boost安装·boost最新版下载·boost安装教程·boost下载安装教程
heeheeai1 个月前
决策树,随机森林,boost森林算法
算法·决策树·随机森林·kotlin·boost
自动驾驶小卡2 个月前
boost::circular_buffer的使用方法简介
c++·boost·circular_buffer
奇树谦3 个月前
踩坑记录:因版本不匹配导致 Boost 1.85 编译失败的完整解决过程
boost
卡戎-caryon6 个月前
【项目实践】boost 搜索引擎
linux·前端·网络·搜索引擎·boost·jieba·cpp-http