因为boost都是使用模板的技术,所以所有代码都是写在一个.hpp头文件中。这样boost中的大部分内容是不需要编译生成相应的链接库,只需要设置下面的包含目录(或者设置一下环境变量),在源文件中包含相应的头文件就可以使用了。少部分库需要生成链接库来使用。

下面介绍完整安装boost库的方法:

1、首先到boost官网去下载最新的版本的boost库:

http://www.boost.org/

2、解压文件,在命令提示符中打开到boost库的根目录下:

双击bootstrap.bat文件,生成bjam.exe,执行以下命令:

bjam --toolset=msvc --build-type=complete stage

或者直接双击bjam.exe.

等待程序编译完成,大约要两个小时左右,会在boost根目录下生成bin.v2和stage两个文件夹,其中bin.v2下是生成的中间文件,大小在2.7G左右,可以直接删除。stage下才是生成的dll和lib文件。

3、打开vs:

视图->属性管理器->当前项目->Debug|Win32->Microsoft.Cpp.Win32.user双击

在弹出的属性对话框中:

通用属性->VC++目录:"包含目录": boost的根目录,例: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0

"库目录": stage下的链接库目录,例:D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

通用属性->链接器->常规:"附加库目录":同上面的"库目录",例:D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

至此环境就配置好了,下面测试一下:

  1. <span style="font-size:14px;"><pre name="code" class="cpp"><span style="font-family:Courier New;">#include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4. #include <iterator>
  5. #include <algorithm>
  6. #include <boost/timer.hpp>
  7. #include <boost/progress.hpp>
  8. #include <libs/date_time/src/gregorian/greg_names.hpp>
  9. #include <libs/date_time/src/gregorian/date_generators.cpp>
  10. #include <libs/date_time/src/gregorian/greg_month.cpp>
  11. #include <libs/date_time/src/gregorian/gregorian_types.cpp>
  12. #include <boost/date_time/posix_time/posix_time.hpp>
  13. using namespace boost;
  14. int main()
  15. {
  16. boost::timer t;
  17. boost::progress_display pd(100);
  18. for (int i = 0; i < 100; ++i) //进度条
  19. {
  20. ++pd;
  21. }
  22. boost::gregorian::date dt(2009, 12, 8); //date_time 库
  23. assert(dt.year() == 2009);
  24. assert(dt.day() == 8);
  25. boost::gregorian::date::ymd_type ymd = dt.year_month_day();
  26. std::cout<<"\n"<<ymd.year<<"/"<<ymd.month<<"/"<<ymd.day<<" the day is "
  27. <<dt.day_of_year() <<" days of this year"<< std::endl;
  28. std::cout << boost::gregorian::to_iso_extended_string(dt) << std::endl; //转换为其他格式
  29. std::cout << boost::gregorian::to_iso_string(dt) << std::endl;
  30. std::cout << boost::gregorian::to_simple_string(dt) << std::endl<<std::endl;
  31. //对数组排序操作
  32. std::vector<int> test_vc(100);
  33. std::vector<int>::iterator beg_it = test_vc.begin();
  34. std::vector<int>::iterator end_it = test_vc.end();
  35. std::srand(std::time(NULL));
  36. std::for_each(beg_it, end_it, [](int& n){n = rand(); });
  37. std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
  38. std::cout << std::endl << std::endl;
  39. std::sort(beg_it, end_it, std::greater<int>());
  40. std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
  41. std::cout << std::endl<<std::endl;
  42. boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6));
  43. std::cout << t.elapsed() << "s" << std::endl; //程序运行时间
  44. system("pause");
  45. return 0;
  46. }</span></span>

程序正确运行:

windows下boost库的基本使用方法的更多相关文章

  1. Windows下python库的常用安装方法

    目录:       1.pip安装(需要pip)       2.通过下载whl文件安装(需要pip)       3.在pythn官网下载安装包安装(不需要pip)   方法一:pip安装. 这是最 ...

  2. Windows下静态库与动态库的创建与使用

    Windows下静态库与动态库的创建与使用 学习内容:本博客介绍了Windows下使用Visual C++ 6.0制作与使用静态库与动态库的方法. --------CONTENTS-------- 一 ...

  3. Windows下获取本机IP地址方法介绍

    Windows下获取本机IP地址方法介绍 if((hostinfo = gethostbyname(name)) != NULL) { #if 1 ; printf("IP COUNT: % ...

  4. Windows下mysql忘记密码的解决方法

    Windows下mysql忘记密码的解决方法 mysql5.0 http://www.jb51.net/article/21984.htm方法一: 1.在DOS窗口下输入 net stop mysql ...

  5. windows下重置mysql的root密码方法介绍(转)

    自己在内网操作的,遇到了一些的问题,其中一个是需要重置密码的,所以网上找了两篇文章,都有一些借鉴的地方. 版本mysql5.7.2,linux系统 除了参考文章还有几点说明: service mysq ...

  6. windows下git库的ssh连接,使用public key的方法

    在windows下进行项目开发,使用git,通过ssh方式与git库连接,而ssh方式用public key实现连接. 首先需要下载mygit,安装后使用git bash.git bash(有GUI界 ...

  7. Windows下动态库的隐式调用

    多年的工作经验告诉我Windows下使用动态库最简单的方法:使用def导出函数,然后隐式调用. 具体做法如下: (1)首先使用visual studio 创建“Win32项目”,如下图: (2)然后在 ...

  8. Linux 下 boost 库的安装,配置个人环境变量

    部分引自: https://blog.csdn.net/this_capslock/article/details/47170313 1. 下载boost安装包并解压缩到http://www.boos ...

  9. c++动态库封装及调用(2、windows下动态库创建)

    DLL即动态链接库(Dynamic-Link Libaray)的缩写,相当于Linux下的共享对象.Windows系统中大量采用了DLL机制,甚至内核的结构很大程度依赖与DLL机制.Windows下的 ...

随机推荐

  1. API读取和处理的文件

    1.FileList对象  FileList对象是File对象的一个集合,设置multiple就可以多文件上传.2.Blob对象 Blob对象就是一个二进制原始数据对象,它提供了slice方法可以读取 ...

  2. java加密与解密

    1.下载:UnlimitedJCEPolicy    主要:获取权限文件2.把解压后的      local_policy.jar      US_export_policy.jar   复制到 这个 ...

  3. urllib,urllib2,requests对比

    #coding:utf-8 import urllib2 import urllib import httplib import socket import requests #实现以下几个方面内容: ...

  4. mave之:java的web项目必须要的三个jar的pom形式

    jsp-api javax.servlet-api jstl <!-- jsp --> <dependency> <groupId>javax.servlet< ...

  5. 请让页面中的一个元素(10px*10px)围绕坐标(200, 300) 做圆周运动

    <!DOCTYPE html> <html> <head> <title>Making things move</title> <me ...

  6. 重力感应操控(unity iphone)

    方案一:speed 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public var simulateAcceleromet ...

  7. shell之echo与printf和颜色

    在用户的bashrc中添加一行export来修改提示符.

  8. .net 添加Cookie的4种方法

    第一种添加Cookie方法 HttpCookie myCookie = new HttpCookie("userrole"); myCookie.Values["a&qu ...

  9. 创建对象的最好方式&最好的继承机制(代码实例)

    /* 创建对象的最好方式:混合的构造函数/原型方式, *用构造函数定义对象的所有非函数属性,用原型方式定义对象的函数属性(方法) */ function People(sname){ this.nam ...

  10. SwitchyOmega

    SwitchyOmega下载安装地址: http://switchyomega.com/download.html GFWList.bak.txt教程 {"+GFWed":{&qu ...