名稱空間
變體
操作

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

來自 cppreference.com
< 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) [編輯]