Boost库使用前的操作
1、先去官网下载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




