std::chrono::duration<Rep,Period>::count
来自 cppreference.com
constexpr rep count() const; |
(自 C++11 起) | |
返回此持续时间的刻度数。
内容 |
[编辑] 参数
(无)
[编辑] 返回值
此持续时间的刻度数。
[编辑] 示例
运行此代码
#include <chrono> #include <iostream> int main() { std::chrono::milliseconds ms{3}; // 3 milliseconds // 6000 microseconds constructed from 3 milliseconds std::chrono::microseconds us = 2 * ms; // 30Hz clock using fractional ticks std::chrono::duration<double, std::ratio<1, 30>> hz30(3.5); std::cout << "3 ms duration has " << ms.count() << " ticks\n" << "6000 us duration has " << us.count() << " ticks\n" << "3.5 30Hz duration has " << hz30.count() << " ticks\n"; }
输出
3 ms duration has 3 ticks 6000 us duration has 6000 ticks 3.5 30Hz duration has 3.5 ticks
[编辑] 另请参阅
(C++11) |
将持续时间转换为另一个,具有不同的刻度间隔 (函数模板) |