有如下代码
#include <chrono>
#include <filesystem>
#include <iostream>
#include <ctime>
int main()
{
std::filesystem::path p = "C:\\Windows\\win.ini";
// std::filesystem::path p = "/etc/os-release";
std::filesystem::file_time_type ftime = std::filesystem::last_write_time(p);
std::chrono::system_clock::time_point sys_time = std::chrono::file_clock::to_sys(ftime);
std::time_t cftime = std::chrono::system_clock::to_time_t(sys_time);
std::cout << std::ctime(&cftime);
return 0;
}
在 MSYS2 中编译,用 g++ 下编译成功,但用 clang++ 编译失败,报如下错误
13|error: no viable conversion from 'time_point<[...], duration<__int128, ratio<[...], 1000000000>>>' to 'time_point<[...], duration<long long, ratio<[...], 1000000>>>'|
所用 clang++ 版本为
$ clang++ --version
clang version 16.0.2
Target: x86_64-w64-windows-gnu
Thread model: posix
看起来只是 time_point 的 duration 类型不一致,但试了 time_point_cast 没有成功!
请教如何类型装换?clock_cast 还是 clock_time_conversion? 抑或是 clang++ 的版本问题?
谢谢!
--
FROM 220.203.221.*