我想知道是否有任何方法可以只获取时间而不打印单位:
#include <boost/chrono.hpp>
#include <iostream>
boost::chrono::milliseconds sumGlobal;
int main() {
boost::chrono::high_resolution_clock::time_point t1 ;
boost::chrono::high_resolution_clock::time_point t2 ;
for (i=0;i<10;i++)
{
t1 = boost::chrono::high_resolution_clock::now();
f(); //to waste time
t2 = boost::chrono::high_resolution_clock::now();
sumGlobal += (boost::chrono::duration_cast<boost::chrono::milliseconds>(t2-t1));
}
std::cout << sumGlobal << "\n";
}
输出是:
123 milliseconds
我只想得到
123
有什么解决办法吗?