Windows環境下使用Boost


一、 下載boost

1、boostpro

http://www.boostpro.com/download/

2、boost.org(本文下載方式)

http://www.boost.org/users/download/

http://sourceforge.net/projects/boost/files/boost/1.51.0/

boost_1_51_0.zip 下載並解壓到C盤根文件夾

二、編譯boost

1、生成生命行程序

  執行bootstrap.bat

2、編譯

  執行b2.exe,完成后顯示:

The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
    C:/boost_1_51_0
The following directory should be added to linker library paths:
    C:\boost_1_51_0\stage\lib

三、使用boost

1、創建一個win32 console

2、引用bootst

  C/C++ -> Additional Include Directories: C:\boost_1_51_0
  Linker-> Additional Library Directories: C:\boost_1_51_0\stage\lib
  Linker->Input->Additional Dependencies :libboost_signals-vc110-mt-gd-1_51.lib;libboost_regex-vc110-mt-gd-1_51.lib;

3、Code如下:

#include "stdafx.h"
#include <boost/regex.hpp>
#include <boost/signals.hpp>
#include <boost/lambda/lambda.hpp> 

#include <iostream> 
#include <cassert> 
 
struct print_sum { 
  void operator()(int x, int y) const { std::cout << x+y << std::endl; } 
}; 
 
struct print_product {
 
  void operator()(int x, int y) const { std::cout << x*y << std::endl; }
 
};

int _tmain(int argc, _TCHAR* argv[])
{
    boost::signal2<void, int, int, boost::last_value<void>, std::string> sig;
    sig.connect(print_sum());
    sig.connect(print_product());
    sig(3, 5);
    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;     
    }
	return 0;
}

  

 示例程序在vs2012下通過,輸出:

8
15


免責聲明!

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



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