如何获取持续时间,如int毫秒和浮动秒从< chrono>? [英] How to get duration, as int milli's and float seconds from <chrono>?
问题描述
我想要一个 Duration frameStart;
和
持续时间frameDelta;
(帧间时间) 我需要能够得到 frameDelta
持续时间为毫秒和浮动秒。
这与新的c ++ 11 < chrono>
库?我一直在做它和谷歌(信息是稀疏)。
代码是非常模板化的,需要特殊的转换和事情,我不知道如何正确使用这个库。这是你要找的吗?
#include< chrono>
#include< iostream>
int main()
{
typedef std :: chrono :: high_resolution_clock时间;
typedef std :: chrono :: milliseconds ms;
typedef std :: chrono :: duration< float> fsec;
auto t0 = Time :: now();
auto t1 = Time :: now();
fsec fs = t1 - t0;
ms d = std :: chrono :: duration_cast< ms>(fs);
std :: cout<< fs.count()< s\\\
;
std :: cout<< d.count()<< ms\\\
;
}
其中打印出:
6.5e-08s
0ms
I'm trying to use chrono library for timers and durations.
I want to be able to have a Duration frameStart;
( from app start )
and a Duration frameDelta;
( time between frames )
I need to be able to get the frameDelta
duration as milliseconds and float seconds.
How do you do this with the new c++11 <chrono>
libraries? I've been working on it and googling ( information is sparse ). The code is heavily templated and requires special casts and things, I can't figure out how to use this library correctly.
Is this what you're looking for?
#include <chrono>
#include <iostream>
int main()
{
typedef std::chrono::high_resolution_clock Time;
typedef std::chrono::milliseconds ms;
typedef std::chrono::duration<float> fsec;
auto t0 = Time::now();
auto t1 = Time::now();
fsec fs = t1 - t0;
ms d = std::chrono::duration_cast<ms>(fs);
std::cout << fs.count() << "s\n";
std::cout << d.count() << "ms\n";
}
which for me prints out:
6.5e-08s
0ms
这篇关于如何获取持续时间,如int毫秒和浮动秒从< chrono>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!