首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::chrono::duration::operators (%=)

(1)

duration& operator+=(const duration& d);

(until C++17)

constexpr duration& operator+=(const duration& d);

(since C++17)

(2)

duration& operator-=(const duration& d);

(until C++17)

constexpr duration& operator-=(const duration& d);

(since C++17)

(3)

duration& operator*=(const rep& rhs);

(until C++17)

constexpr duration& operator*=(const rep& rhs);

(since C++17)

(4)

duration& operator/=(const rep& rhs);

(until C++17)

constexpr duration& operator/=(const rep& rhs);

(since C++17)

(5)

duration& operator%=(const rep& rhs);

(until C++17)

constexpr duration& operator%=(const rep& rhs);

(since C++17)

(6)

duration& operator%=(const duration& rhs);

(until C++17)

constexpr duration& operator%=(const duration& rhs);

(since C++17)

在具有相同期间的两个工期之间或在工期与滴答计数值之间执行复合赋值。

如果rep_成员变量保存此持续时间对象中的滴答数,

1%29相当于rep_ += d.count(); return *this;

2%29相当于rep_ -= d.count(); return *this;

3%29相当于rep_ *= rhs; return *this;

4%29相当于rep_ /= rhs; return *this;

5%29相当于rep_ %= rhs; return *this;

6%29相当于rep_ %= d.count(); return *this;

参数

d

-

duration on the right-hand side of the operator

rhs

-

number of ticks on the right-hand side of the operator

返回值

修改后对此持续时间的引用。

二次

代码语言:javascript
复制
#include <chrono>
#include <iostream>
 
int main()
{
    std::chrono::minutes m(11);
    m *= 2;
    m += std::chrono::hours(10); // hours implicitly convert to minutes
    std::cout << m.count() << " minutes equals "
              << std::chrono::duration_cast<std::chrono::hours>(m).count() 
              << " hours and ";
    m %= std::chrono::hours(1);
    std::cout << m.count() << " minutes\n";
}

二次

产出:

二次

代码语言:javascript
复制
622 minutes equals 10 hours and 22 minutes

二次

另见

operator++operator++(int)operator--operator--(int)

increments or decrements the tick count (public member function)

operator+operator-operator*operator/operator%

implements arithmetic operations with durations as arguments (function template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券