如何使用chrono返回持续时间类型

How to return a duration type using chrono

本文关键字:持续时间 类型 返回 chrono 何使用      更新时间:2023-10-16

我正在编写一个类函数,该函数使用chrono库返回以微秒为单位的持续时间。

std::chrono::duration<std::chrono::miroseconds> stop_watch::get_time() {
   auto length = std::chrono::duration_cast<std::chrono::microseconds>(stop_time - start_time);
   return length;
}

由于某种原因,我的编译器向我吐了。感谢所有的帮助,谢谢!

std::chrono::microseconds
stop_watch::get_time()
{
   using namespace std::chrono;
   return duration_cast<microseconds>(stop_time - start_time);
}