我有一个使用 date.h 库在 C++14 下工作的函数,但我正在将程序转换为使用 C++20,但它不再工作。请问我做错了什么?
我的C++14/date.h代码如下:
#include <date/date.h> // latest, installed via vcpkg
#include <chrono>
auto StringToUnix(const std::string& source) -> std::time_t
{
auto in = std::istringstream(source);
auto tp = date::sys_seconds{};
in >> date::parse("%Y-%m-%d %H:%M:%S", tp);
return std::chrono::system_clock::to_time_t(tp);
}
我转换后的C++20函数如下:
#include <chrono>
auto StringToUnix(const std::string& source) -> std::time_t
{
using namespace std::chrono;
auto in = std::istringstream(source);
auto tp = sys_seconds{};
in >> parse("%Y-%m-%d %H:%M:%S", tp);
return system_clock::to_time_t(tp);
}
我在 VS2019 社区(最新)中收到的错误是:
E0304 no instance of overloaded function "parse" matches the argument list
是否有任何细微的变化是我遗漏的?请问是什么原因导致这个错误?
规范中有一个错误正在修复中。 VS2019忠实地再现了该规范。将格式字符串包含在string{}
,或者给它一个尾随s
将其转换为字符串,这将解决该错误。
in >> parse("%Y-%m-%d %H:%M:%S"s, tp);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)