# std::chrono::duration<Rep,Period>::count

< cpp‎ | chrono‎ | duration

constexpr rep count() const; |  |

返回此 duration 的计次数。

### 参数

（无）

### 返回值

此 duration 的计次数。

### 示例

    #include <chrono>
    #include <iostream>
    int main()
    {
        std::chrono::milliseconds ms{3}; // 3 毫秒
        // 从 3 毫秒构造 6000 微秒
        std::chrono::microseconds us = 2*ms;
        // 使用分数计次的 30Hz 时钟
        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

### 参阅

duration_cast (C++11) | 转换时长到另一个拥有不同嘀嗒间隔的时长 (函数模板)