小编Dar*_*der的帖子

high_resolution_clock错误:无法将'std :: ostream {aka std :: basic_ostream <char>}'左值绑定到'std :: basic_ostream <char> &&'

如何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++

0
推荐指数
1
解决办法
415
查看次数

标签 统计

c++ ×1