C++一直缺乏对时间和日期的处理能力,一般借助于C的struct tm和time();timer包含三个类其中timer,progress_timer是计时器类,进度指示类是progress_display.

1.timer类,内部封装的是std::clock,精度依赖于具体的编译器和操作系统。只能计算从声明对象到对象结束的时间。

#include <iostream>
#include <boost/timer.hpp>
using namespace std;
using namespace boost; int main()
{
timer t;
cout << "max timespan:" << t.elapsed_max()/3600<<"h"<<endl;//支持的最大时间
cout << "min timespan:" << t.elapsed_min() << "s" <<endl;//支持的最小时间
cout << "now time elapsed" << t.elapsed() << "s" << endl;//已经流逝的时间
return 0; }

2.progress_timer继承与timer但是不需要显示调用elapsed当对象退出作用域时会自动调用。

#include <iostream>
#include <boost/progress.hpp>
#include <boost/thread.hpp>
using namespace std;
using namespace boost; int main()
{
progress_timer t; this_thread::sleep(posix_time::seconds(2)); return 0; }

3.progress_display类用于在标准输出显示进度

#include <iostream>
#include <fstream>
#include <vector>
#include <boost/progress.hpp>
using namespace std;
using namespace boost; int main()
{
vector<string> vec(100000);
fstream fs("c:\\test.txt");
progress_display pd(vec.size());
for (vector<string>::iterator pos = vec.begin();pos != vec.end();++pos)
{
fs << *pos <<endl;
++pd;
} return 0; }

boost之时间timer的更多相关文章

  1. boost.asio系列——Timer

    同步Timer asio中提供的timer名为deadline_timer,它提供了超时计时的功能.首先以一个最简单的同步Timer为例来演示如何使用它. #include<iostream&g ...

  2. 【Boost】boost库中timer定时器 1

    博客转载自:http://blog.csdn.net/liujiayu2/article/details/50384537 同步Timer asio中提供的timer名为deadline_timer, ...

  3. Boost中的Timer的使用——计算时间流逝

    使用Boost中的Timer库计算程序的运行时间 程序开发人员都会面临一个共同的问题,即写出高质量的代码完毕特定的功能.评价代码质量的一个重要标准就是算法的运行效率,也就是算法的运行时间.为了可靠的提 ...

  4. 【Boost】boost库中timer定时器 2

    博客转载自:http://blog.csdn.net/yockie/article/details/40386145 先跟着boost文档中asio章节的指南中的几个例子学习一下使用: 所有的Asio ...

  5. Python基础学习笔记(十)日期Calendar和时间Timer

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-date-time.html 3. http://www.liao ...

  6. 利用boost获取时间并格式化

    利用boost来获取当前时间又方便快捷,还不用考虑跨平台的问题. 1. 输出YYYYMMDD #include <boost/date_time/gregorian/gregorian.hpp& ...

  7. [Boost]boost的时间和日期处理-(1)日期的操作

    <开篇> Boost.DateTime库提供了时间日期相关的计算.格式化.转换.输入输出等等功能,为C++的编程提供了便利.不过它有如下特点: 1. Boost.DateTime 只支持1 ...

  8. [Boost]boost的时间和日期处理-(2)时间的操作

    <开篇> 本篇紧接着boost上篇叙述Boost::DateTime的时间处理.在C++中,常见的时间有time_t, FILETIME和tm,而boost中用ptime. 构造ptime ...

  9. boost 日期时间计算

    示例代码如下: #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_ ...

随机推荐

  1. HNU 13411 Reverse a Road II(最大流+BFS)经典

    Reverse a Road II Time Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KB Total submit ...

  2. 【LeetCode OJ 016】3Sum Closest

    题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integ ...

  3. CPU亲和力

    http://blog.chinaunix.net/uid-27714502-id-3515874.html http://www.tuicool.com/articles/I7NFzy http:/ ...

  4. C# WEB 不显示目录结构

    <system.webServer> <directoryBrowse enabled="false" /> </system.webServer&g ...

  5. android studio win7开发环境

    java 开发环境 这里使用jdk1.7版本,从官网上下载. 点击.正常的window软件的安装方式,一直下一步即可. 环境变量的设置: 在系统属性中,对需要的环境变量进行设置: JAVA_HOME设 ...

  6. 微信小程序 快键键

    快捷键 格式调整 - Ctrl+S:保存文件 - Ctrl+[, Ctrl+]:代码行缩进 - Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块 - Ctrl+C Ctrl+V:复 ...

  7. poj 3683(2-sat+输出一组可行解)

    题目链接:http://poj.org/problem?id=3683 思路:对于每个结婚仪式,只有在开始或结束时进行这两种选择,我们可以定义xi为真当且仅当在开始时进行.于是我们可以通过时间先后确定 ...

  8. 一些常用的html css整理--文本长度截取

    div+css设置列表div超出部分显示...(单行文本) width:200px; //指定宽度: overflow:hidden; //将超出内容隐藏 text-overflow:ellipsis ...

  9. Java手记

    由于腾讯的MTA只有JAVA的demo,为了测试用php实现的加密算法是否正确,所有只能运行一下Java 配置环境:http://www.runoob.com/java/java-environmen ...

  10. eclipse 4.3 汉化

    打开浏览器,浏览“参考资料”内给出的“eclipse语言包下载”地址,在博客新页面找到地址链接,如图所示.“Babel Language...”开头的一栏下面就是各个eclise版本的语言包,此处以I ...