1. 程式人生 > >VS2013中BOOST庫的環境配置與使用

VS2013中BOOST庫的環境配置與使用

&1 安裝Boost

檔案下載:連結:http://pan.baidu.com/s/1kUKaOFP 密碼:auf2

解壓之後放到你想安裝的資料夾內,我的是在C:\Program Files\boost\boost_1_60_0中。

&2 執行bootstrap.bat檔案

以管理員許可權執行cmd,切換到boost目錄,執行bootstrap.bat檔案,結果如下所示:

&3 資料夾內會生成一個bjam.exe檔案,下一步就是執行它

結果如下圖所示:

&4 配置VS2013

  • 專案右鍵單擊->屬性->C/C++->附加包含目錄

    配置的目錄為:C:\Program Files\boost\boost_1_60_0

  • 專案鍵單擊->屬性->連結器->附加庫目錄

    配置目錄:C:\Program Files\boost\boost_1_60_0\libs

&5 測試程式碼

 1 #include <boost/lexical_cast.hpp> 
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8 using boost::lexical_cast;
 9 int a = lexical_cast<int>("123");
10 double
b = lexical_cast<double>("123.0123456789"); 11 string s0 = lexical_cast<string>(a); 12 string s1 = lexical_cast<string>(b); 13 cout << "number: " << a << " " << b << endl; 14 cout << "string: " << s0 << " " << s1 << endl; 15
int c = 0; 16 try{ 17 c = lexical_cast<int>("abcd"); 18 } 19 catch (boost::bad_lexical_cast& e){ 20 cout << e.what() << endl; 21 } 22 23 system("Pause"); 24 return 0; 25 }
boost測試

&6 程式結果