VS2019配置C++ boost库

一、安装编译BOOST C++libary

1、安装Boost库
官网下载:https://www.boost.org/users/history/version_1_70_0.html
据说低于1.7.0的版本在vs2019中支持不完善,编译或运行时发生不可预料的bug
2、下载好后,使用VS tool中developer Command终端工具对解压之后的文件boostrap.bat进行编译

具体如下: 切换到boost_1_17_0的安装目录: >cd D:/boost_1_17_0 >boostrap.bat #执行

运行的很快,可以在该根目录中增加了几个文件如bjam.exe,b2.exe等文件,如图所示:

继续在命令行终端中执行

bjam.exe --toolset=msvc-14.1 architecture=x86 address-model=64 link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization

稍等片刻,编译完成之后,会提示将在使用Boost库时将两个路径添加到包含目录库目录

#二、配置环境 新建vs2019 C++项目,并添加boost依赖库 >点击菜单栏 项目——>属性——>选择VC++目录,在包含目录 和 库目录添加以上2个路径,如下图:

此时工程配置的基本完成,代码测试:
#include <boost/lexical_cast.hpp>     
#include <iostream>   

using namespace std;
using namespace boost;

int main()
{
	//system("chcp 65001");

	double a = lexical_cast<double>("3.1415926");
	string str = lexical_cast<string>("3.1415926");
	cout << "This is a number: " << a << endl;
	cout << "This is a string: " << str << endl;
	int b = 0;
	try {
		b = lexical_cast<int>("neo");
	}
	catch (bad_lexical_cast& e) {
		cout << e.what() << endl;
	}
	return 0;
}

运行结果:

posted @ 2020-11-21 20:23  牛犁heart  阅读(3075)  评论(0编辑  收藏  举报