【发布时间】:2020-04-04 15:25:53
【问题描述】:
我使用 MSVC2015 为 windows 编写了一个解决方案,其中以下代码转换 std::filesystem::last_write_time 结果 time_t:
time_t ftime = std::file_time_type::clock::to_time_t(fs::last_write_time("/Path/filename"))
效果很好。然后,当我尝试使用 gcc 9.3 (-std=C++2a) 将解决方案移植到 Linux 时,出现以下错误:
错误:'to_time_t' 不是 'std::chrono::time_point::clock' {aka 'std::filesystem::__file_clock'}的成员
我搜索了一个解决方案,但我发现的解决方案是基于 cplusplus.com 的 std::filesystem::last_write_time 示例中包含的解决方案。解决方法如下图:
auto ftime = fs::last_write_time(p);
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
不幸的是,它对我不起作用。实际上,该示例有一条评论说它不适用于 MSVC(在 MSVC2015 工作)或 GCC 9; C++20 将允许可移植输出。
现在,我被困住了……如何使用 gcc 进行这种转换?
【问题讨论】: