首页 > 解决方案 > 在 C++ 中测量时间并写入文件时,'operator<<' 不匹配

问题描述

我编写了一个代码来测量排序算法的运行时间并将时间写入文件,但我不断收到“错误:'operator<<'不匹配(操作数类型是'std :: basic_ostream'和'std ::chrono::duration >')|" 我不知道如何解决它。我的代码片段在这里,错误与数据文件有关:

  auto start=std::chrono::high_resolution_clock::now();
  selectionsort(numberarray, length);
  auto stop=std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop-start);
datafile << length << ';' << duration << endl;

谁能告诉我它有什么问题?谢谢

标签: c++sortingtimeoperator-keyword

解决方案


推荐阅读