现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

VS2010下安装和使用boost库

2014-05-13 08:59 工业·编程 ⁄ 共 1972字 ⁄ 字号 暂无评论

1.去官网www.boost.org下载最新的boost,我下载了boost_1_55_0.zip和boost_1_55_0-msvc-10.0-32.exe。前者是纯净的源码,需要用户自己编译;后者是VS2010已编译的,含源码和编译生成的库。

2.这里只讲诉boost_1_55_0-msvc-10.0-32.exe。安装路径不建议放在C盘,例如D:\tmpcode\boost_1_55_0。安装需要3.4GB硬盘空间。

3.设置Windows的环境变量。推荐使用工具Rapid Environment Editor。http://www.rapidee.com/

环境变量,用户变量组,新建变量名:BOOST,变量值:D:\tmpcode\boost_1_55_0

4.修改VS2010的参数,在项目的解决方案那里找到属性页,打开并选择配置属性,选择VC++目录,设置包含目录和库目录,例如我的为:

包含目录 $(BOOST);$(IncludePath)

库目录 $(BOOST)\lib32-msvc-10.0;$(LibraryPath)

5.至此设置完毕。如果想自行编译源码boost_1_55_0.zip,请参考文章:

http://blog.csdn.net/misskissc/article/details/9793645

6.运行下面程序,测试

#include "stdafx.h"
#include <boost/config.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/tuple/tuple.hpp>
enum family
{ Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };
int main()
{
        using namespace boost;
        const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
               "Margaret", "Benjamin"
        };
        adjacency_list <> g(N);
        add_edge(Jeanie, Debbie, g);
        add_edge(Jeanie, Rick, g);
        add_edge(Jeanie, John, g);
        add_edge(Debbie, Amanda, g);
        add_edge(Rick, Margaret, g);
        add_edge(John, Benjamin, g);
        graph_traits < adjacency_list <> >::vertex_iterator i, end;
        graph_traits < adjacency_list <> >::adjacency_iterator ai, a_end;
        property_map < adjacency_list <>, vertex_index_t >::type
               index_map = get(vertex_index, g);
        for (boost::tie(i, end) = vertices(g); i != end; ++i) {
               std::cout << name[get(index_map, *i)];
               boost::tie(ai, a_end) = adjacent_vertices(*i, g);
               if (ai == a_end)
                       std::cout << " has no children";
               else
                       std::cout << " is the parent of ";
               for (; ai != a_end; ++ai) {
                       std::cout << name[get(index_map, *ai)];
                       if (boost::next(ai) != a_end)
                               std::cout << ", ";
               }
               std::cout << std::endl;
        }
        return EXIT_SUCCESS;
}

给我留言

留言无头像?