命名空间
变体
操作

std::chrono::year::operator+=, std::chrono::year::operator-=

来自 cppreference.cn
< cpp‎ | chrono‎ | year
 
 
 
 
constexpr std::chrono::year& operator+=( const std::chrono::years& y ) noexcept;
(1) (C++20 起)
constexpr std::chrono::year& operator-=( const std::chrono::years& y ) noexcept;
(2) (C++20 起)

从年份值中增加或减去 y.count() 年。

1) 等价于 *this = *this + y;
2) 等价于 *this = *this - y;

目录

[编辑] 返回值

修改后此 year 的引用。

[编辑] 注意

如果结果超出范围 [-3276732767],则实际存储的值未指定。

[编辑] 示例

#include <chrono>
#include <iostream>
 
int main()
{
    using namespace std::literals::chrono_literals;
    std::cout << std::boolalpha;
 
    std::chrono::year y{2020};
 
    y += std::chrono::years(12);
    std::cout << (y == 2032y) << ' ';
 
    y -= std::chrono::years(33);
    std::cout << (y == 1999y) << '\n';
}

输出

true true

[编辑] 参阅

递增或递减年份
(public member function) [编辑]
year 进行算术运算
(function) [编辑]