我已经创建了一个时间点,但我一直在努力将它打印到终端.
#include <iostream>
#include <chrono>
int main(){
//set time_point to current time
std::chrono::time_point<std::chrono::system_clock,std::chrono::nanoseconds> time_point;
time_point = std::chrono::system_clock::now();
//print the time
//...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我可以在这里找到打印time_point的唯一文档:http://en.cppreference.com/w/cpp/chrono/time_point
但是,我甚至无法根据我的time_point创建time_t(如示例所示).
std::time_t now_c = std::chrono::system_clock::to_time_t(time_point); //does not compile
Run Code Online (Sandbox Code Playgroud)
错误:
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/chrono: In instantiation of ‘constexpr std::chrono::time_point<_Clock, _Dur>::time_point(const std::chrono::time_point<_Clock, _Dur2>&) [with _Dur2 = std::chrono::duration<long int, std::ratio<1l, 1000000000l> >; _Clock = std::chrono::system_clock; _Dur = std::chrono::duration<long int, std::ratio<1l, 1000000l> >]’:
time.cpp:13:69: required from here
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/chrono:540:32: error: no matching function for call to ‘std::chrono::duration<long int, std::ratio<1l, 1000000l> >::duration(std::chrono::time_point<std::chrono::system_clock, …Run Code Online (Sandbox Code Playgroud)