早聽說boost的大名。今天嘗試了一下,期間僅遇到了一個小問題,網上搜索無果後,自己嘗試成功解決,望可以幫助其他人。
在官網下載下來後http://www.boost.org/,版本是1.55.0,廢話不說,開搞。
按照官網上的Get Started步驟,一步步弄。在vs下進行
首先,解壓。------時間不短。
然後第一個程序成功,很容易。就是配置配置工程屬性,然後調用boost裏東西。只要不是英語文盲都應該沒問題。
然後到了下一步,
Prepare to Use a Boost Library Binary。這是幹什麼呢?If you want to use any of the separately-compiled Boost libraries, you'll need to acquire library binaries.由於Boost中有一些庫是需要單獨構建的。好的沒問題按照步驟來
If you wish to build from source with Visual C++, you can use a simple build procedure described in this section. Open the command prompt and change your current directory to the Boost root directory. Then, type the following commands:
bootstrap .\b2
The first command prepares the Boost.Build system for use. The second command invokes Boost.Build to build the separately-compiled Boost libraries. Please consult theBoost.Build documentation for a list of allowed options.
這裏我直接到了boost目錄中運行的bootstrap.bat,然後纔在命令行裏敲 .\b2
本以爲,這個步驟也是很easy,沒想到時間還挺長。然後樓主很興奮的關掉了控制檯。沒有注意的其中的內容,這位我之後的問題埋下伏筆。然後測試官網給的第二個例子。哎呀問題來了。
- 在Right-click example in the Solution Explorer pane and selectProperties from the resulting pop-up menu
- In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g.C:\Program Files\boost\boost_1_55_0\lib\.
- From the Build menu, select Build Solution.
在以上步驟之後,(在第一個範例中我已更改了包含目錄)也就是修改了附加庫目錄之後。運行程序。
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
其中boost::regex就是一個需要單獨built的庫。
我受到了一個鏈接錯誤
LINK : fatal error LNK1104: 無法打開文件“libboost_regex-vc110-mt-gd-1_55.lib”哎?再次檢查自己之前的步驟,沒有問題呀。然後百度、google一頓搜。
方法都試了不行。然後我又嘗試build boost。一段時間等待之後。我看到了控制檯最後的內容。大意就是恭喜成功。然後給了各路徑
C:\Users\Mr.Guo\Downloads\boost_1_55_0\stage\lib
我類個去,這東西原來沒有的呀。然後鏈接附加庫目錄修改爲改路徑。程序運行成功
希望自己能夠堅持下去,鑽研一下這個Boost。