●timer库

#include <boost\timer.hpp>
#include <boost\progress.hpp>

1、timer类

// timer类的示例。
void Lib_Demo_timer::Demo_timer()
{
timer t; cout << "可度量的最大单位:" << t.elapsed_max() / 3600 << "小时" << endl;
cout << "可度量的最小单位:" << t.elapsed_min() << "s" << endl;
cout << "计时开始...按任意键计时" << endl;
system("pause");
cout << "已经过的时间:" << t.elapsed() << "s" << endl;
}

输出:

可度量的最大单位:596.523小时

可度量的最小单位:0.001s

计时开始...按任意键计时

请按任意键继续. . .

已经过的时间:0.74s

请按任意键继续. . .

2、process类

// progress类的示例。
void Lib_Demo_timer::Demo_process(void)
{
{
boost::progress_timer t;
cout << "需要计时的代码块1" << endl;
system("pause");
} stringstream ss;
{
boost::progress_timer t(ss);
cout << "需要计时的代码块2" << endl;
system("pause");
}
cout << ss.str() << endl;
}

输出:

需要计时的代码块1

请按任意键继续. . .

0.96 s

需要计时的代码块2

请按任意键继续. . .

1.66 s

请按任意键继续. . .

3、progress_display类

// progress_display类的示例。
void Lib_Demo_timer::Demo_progress_display(void)
{
vector<string> v(100); progress_display pd(v.size()); for(vector<string>::const_iterator i = v.begin(); i != v.end(); ++i)
{
//针对i的处理
Sleep(100); ++pd;
} }

输出:

0%   10   20   30   40   50   60   70   80   90   100%

|----|----|----|----|----|----|----|----|----|----|

***************************************************

请按任意键继续. . .

●date_time库

1、引用库的方式

(1)、包含源码的方式:通过启用宏 BOOST_DATE_TIME_SOURCE 等。

#define BOOST_DATE_TIME_SOURCE
#define BOOST_DATE_TIME_NO_LIB #include <libs/date_time/src/gregorian/greg_names.hpp>
#include <libs/date_time/src/gregorian/date_generators.cpp>
#include <libs/date_time/src/gregorian/greg_month.cpp>
#include <libs/date_time/src/gregorian/greg_weekday.cpp>
#include <libs/date_time/src/gregorian/gregorian_types.cpp>

注意:如果使用的boost版本较高,那么在使用(较低版本)STLport标准库时会编译错误,解决方法是使用VC的标准库。

(2)、包含已编译库的方式

#include <boost/date_time/gregorian/gregorian.hpp>

需要在项目配置的“库目录”中增加boost编译库的路径。

2、定义日期对象 date

头文件

#include <boost/date_time/gregorian/gregorian.hpp>
    // date 初始化示例
boost::gregorian::date d1; //默认创建一个 无效日期
//宏 DATE_TIME_NO_DEFAULT_CONSTRUCTOR 可以禁用 构造无效日期的 默认构造函数
date d2(2010, 1, 1);
date d3(2000, Jan, 1); //使用英文指定月份
date d4(d2); assert(d1 == date(boost::date_time::special_values::not_a_date_time));
assert(d2 == d4); //date支持比较操作
assert(d3 < d4);
//从字符串创建
//注意:包含源码是依赖 #include <libs/date_time/src/gregorian/greg_month.cpp>
date d1_1 = boost::gregorian::from_string("1999-12-31");
date d2_1(boost::gregorian::from_string("2005/1/1"));
date d3_1 = boost::gregorian::from_undelimited_string("20011118");
//使用 day_clock 创建,返回当天日期对象,注意:依赖操作系统的时区设置
cout << boost::gregorian::day_clock::local_day() << endl;
cout << day_clock::local_day_ymd << endl;
cout << day_clock::universal_day() << endl;
cout << day_clock::universal_day_ymd << endl;
//创建特殊日期
date d1_2(special_values::neg_infin); //负无限日期
date d2_2(special_values::pos_infin); //正无限日期
date d3_2(special_values::not_a_date_time); //无效日期
date d4_2(special_values::max_date_time); //最大可能日期9999-12-31
date d5_2(special_values::min_date_time); //最小可能日期1400-01-01
//异常创建,boost会抛出异常。
date d1_3(1399, 12, 1);
date d2_3(10000, 1, 1);
date d3_3(2010, 2, 29);

最新文章

  1. .NET平台开源项目速览(18)C#平台JSON实体类生成器JSON C# Class Generator
  2. HTML 内容居中方式总结
  3. 【Filter 不登陆无法访问】web项目中写一个过滤器实现用户不登陆,直接给链接,无法进入页面的功能
  4. 怎样让webservice在浏览器远程浏览时像在本地浏览一样有参数输入框
  5. 默认选中ComboBox的某一项
  6. socket,TCP/IP的理解
  7. HDU 1226 BFS
  8. servlet和struts2一起使用,实现绝对路径下的图片输出到jsp页面
  9. MVC 无法将类型“System.Collections.Generic.List&lt;AnonymousType#1&gt;”隐式转换为“System.Collections.Generic.IList&lt;Mvc3Modeltest.Models.Movie&gt;”。存在一个显式转换(是否缺少强制转换?))
  10. AFNetworking源码阅读
  11. 1、AngularJS 验证
  12. Log4net快速配置使用指南。(快速搭建log4net日志平台手册)
  13. 【Beta】阶段 第三次Daily Scrum Meeting
  14. 使用Xmanager通过XDMCP连接远程Centos 7 (摘自xmanager官方博客)
  15. JS的数据类型及转换(还是基础的东西)
  16. SpringBoot的配置文件加载顺序和使用方式
  17. 【图文详解】HDFS基本原理
  18. 第八周学习笔记-ADO.Net中DataTable的应用
  19. 今天看了几个小时的微信小程序说说心得体会
  20. SSH三大框架的工作原理

热门文章

  1. JS判断字符串是否为空、过滤空格、查找字符串位置等函数集
  2. UNIX时间戳及日期的转换与计算
  3. php curl 基本用法
  4. Python 改变当前工作目录
  5. oracle 数据库连接的四种方式
  6. noi 04:网线主管
  7. Android 中如何使用动画
  8. BZOJ 2693 jzptab
  9. COJ 0999 WZJ的数据结构(负一)
  10. BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支