year_month
클래스
월 및 연도를 나타냅니다. 날짜가 지정되지 않았습니다.
구문
class year_month; // C++20
멤버
속성 | 설명 |
---|---|
생성자 | a 생성 year_month |
year |
연도를 반환합니다. |
month |
월을 반환합니다. |
ok |
값과 month 값이 year 유효한 범위에 있는지 확인합니다. |
operator+= |
지정된 월 또는 연도 수를 추가합니다. |
operator-= |
지정한 월 또는 연도 수를 뺍니다. |
비멤버
속성 | 설명 |
---|---|
from_stream |
지정된 형식을 year_month 사용하여 스트림에서 구문 분석 |
operator+ |
월 및/또는 연도를 추가합니다. |
operator- |
월 및/또는 연도를 뺍니다. |
operator== |
두 year_month 값이 같은지 여부를 확인합니다. |
operator<=> |
두 year_month 값을 비교합니다. >, >=, <=, <, != 연산자는 컴파일러에 의해 합성됩니다. |
operator<< |
스트림에 출력 year_month 합니다. |
요구 사항
헤더: <chrono>
(C++20 이후)
네임스페이스: std::chrono
컴파일러 옵션: /std:c++latest
생성자
를 생성합니다 year_month
.
1) year_month() = default;
2) constexpr year_month(const year& y, const month& m) noexcept;
매개 변수
y
year
값입니다.
m
month
값입니다.
설명
1) 기본 생성자는 또는 month
값을 초기화 year
하지 않습니다.
2) 지정된 값을 사용하여 생성 year_month
합니다.
날짜를 지정하는 C++20 구문에 대한 자세한 내용은 operator/
예: year_month
만들기
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month ym{2021y / June};
std::cout << ym;
return 0;
}
2021/Jun
month
월을 가져옵니다.
constexpr month month() const noexcept;
반환 값
month
값입니다.
year
연도를 가져옵니다.
constexpr year year() const noexcept;
반환 값
year
.
ok
이 값에 저장된 연도 및 월 값이 year_month
모두 유효한 범위에 있는지 확인합니다.
constexpr bool ok() const noexcept;
반환 값
true
연도 및 월 값이 year_month
유효한 범위에 있으면 false
입니다.
operator+=
에 year_month
월 또는 연도를 추가합니다.
1) constexpr year_month& operator+=(const months& dm) noexcept;
2) constexpr year_month& operator+=(const years& dy) noexcept;
매개 변수
dm
추가할 월 수입니다.
dy
추가할 연도 수입니다.
반환 값
*this
- 추가 결과를 반영합니다.
예: operator +=
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month ym{2021y / June};
std::cout << ym << '\n';
ym += months{2};
ym += years{1};
std::cout << ym;
return 0;
}
2021/Jun
2022/Aug
operator-=
에서 year_month
월 또는 연도를 뺍니다.
1) constexpr year_month& operator-=(const months& dm) noexcept;
2) constexpr year_month& operator-=(const years& dy) noexcept;
매개 변수
dm
뺄 월 수입니다.
dy
뺄 연도 수입니다.
반환 값
*this
- 빼기의 결과를 반영합니다.
예: operator -=
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
year_month ym{2021y / June};
std::cout << ym << '\n';
ym -= months{2};
ym -= years{1};
std::cout << ym;
return 0;
}
2021/Jun
2020/Apr
참고 항목
<chrono>
year
year_month_day
year_month_day_last
year_month_weekday
year_month_weekday_last
operator/
헤더 파일 참조