[英]How to get the weekday number from std::chrono::year_month_day in C++
In C++ 20, the following code will output the number (0-6) for the weekday of the input date:在C++ 20,下面的代码将output这个数字(0-6)为输入日期的星期几:
#include <chrono>
#include <iostream>
int
main()
{
using namespace std;
using namespace std::chrono;
year_month_day dmy;
cin >> parse("%d %m %Y", dmy);
cout << format("%w", weekday{dmy}) << '\n';
}
How can I get that number to use in code as a numeric value so I could use it in a calculation?我怎样才能让这个数字在代码中用作数值,以便我可以在计算中使用它? This has to be simple but I can't figure it out.这必须很简单,但我无法弄清楚。
int total_score = weekday{dmy} * 10;
As a side note, I am really using the date ( http://howardhinnant.github.io/date/date.html ) library created by Howard Hinnant in C++ 17 but I believe the same question applies to both.作为旁注,我实际上使用的是 Howard Hinnant 在 C++ 17 创建的日期 ( http://howardhinnant.github.io/date/date.html ) 库,但我相信同样的问题适用于两者。
You can usestd::chrono::weekday::c_encoding
to retrieve the stored value.您可以使用std::chrono::weekday::c_encoding
来检索存储的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.