Three Techniques for Creating a chrono::duration - C++ Data Type

C++ examples for Data Type:time

Description

Three Techniques for Creating a chrono::duration

Demo Code

#include <iostream>
#include <chrono>

using namespace std;

chrono::duration<unsigned long long> operator"" _m(unsigned long long Value)
{
    return chrono::duration<int, ratio<60>>(Value);
}

int main()/*from   w  w w  .j  av a 2 s . c  o  m*/
{
    typedef chrono::duration<double, ratio<1, 5>> fifths;

    // Define an interval of 20 minutes.
    chrono::duration<int, ratio<60>>StdTime(20);
    auto AutoTime(20_m);

    auto UDLTime(20min);

    // Output the time in seconds.
    cout << chrono::duration_cast<chrono::seconds>(StdTime).count() << endl;

    cout << chrono::duration_cast<chrono::seconds>(AutoTime).count() << endl;

    cout << chrono::duration_cast<chrono::seconds>(UDLTime).count() << endl;

    return 0;
}

Result


Related Tutorials