如何high_resolution_clock在C++中打印?
#include <iostream>
#include <chrono>
typedef std::chrono::high_resolution_clock high_resolution_clock;
int main()
{
std::cout << high_resolution_clock::now() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
建立以上结果:
/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;
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
和
/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;
^
Run Code Online (Sandbox Code Playgroud)
看完这个答案后,我试图迭代"容器":
#include <iostream>
#include <chrono>
typedef std::chrono::high_resolution_clock high_resolution_clock;
int main()
{
for(auto i: …Run Code Online (Sandbox Code Playgroud) c++ ×1