一、安裝編譯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進行編譯
運行的很快,可以在該根目錄中增加了幾個文件如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庫時將兩個路徑添加到包含目錄和庫目錄中
#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;
}
運行結果: