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;
}

運行結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM