How to print the high_resolution_clock
in C++?
#include <iostream>
#include <chrono>
typedef std::chrono::high_resolution_clock high_resolution_clock;
int main()
{
std::cout << high_resolution_clock::now() << std::endl;
}
Building the above results in:
/home/greg/repositories/firstProject/main.cpp:27: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘std::chrono::_V2::system_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000000l> > >}’)
std::cout << high_resolution_clock::now() << std::endl;
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and
/home/greg/repositories/firstProject/main.cpp:27: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
std::cout << high_resolution_clock::now() << std::endl;
^
After reading this answer I tried to iterate over the "container":
#include <iostream>
#include <chrono>
typedef std::chrono::high_resolution_clock high_resolution_clock;
int main()
{
for(auto i: high_resolution_clock::now()){
std::cout << i << std::endl;
}
}
However this resulted in even more errors. I also tried using printf
and casting high_resolution_clock::now()
to a long long
with no success.
Update:
Trying another answer suggested here also yielded more errors:
#include <iostream>
#include <chrono>
typedef std::chrono::high_resolution_clock high_resolution_clock;
int main()
{
auto i = high_resolution_clock::now();
std::cout << i.time_since_epoch() << std::endl;
}