1.下載安裝Boost庫
我們這裏採用最簡單的安裝方法,下載預編譯庫,具體下載方法如下:
- 打開boost庫的官方網站
下載好後解壓即可,我下載到了D盤。
2.VS2017配置Boost庫
- 我們下載的是64位的Boost庫,因此平臺得是64位;
- 我們修改配置的項目是建立在上篇文章的基礎上 ;
1.配置C/C++附加庫目錄
2.配置鏈接器附加庫目錄
3.運行代碼
輸入以下代碼:
#include <boost/lexical_cast.hpp>
#include <iostream>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try{
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e){
cout << e.what() << endl;
}
return 0;
}
運行結果如下:
4.VS2017導出項目模板一勞永逸
已在上篇文章中所述,按照此過程配置的最終項目文件可在以下位置下載:https://download.csdn.net/download/ustcsunyue/10893873。