由于某些原因,difftime只返回整数。我的代码非常简单。为什么difftime只返回整数?
#include <time.h>
int main()
{
time_t test = time(NULL);
while (1)
{
std::cout << difftime(time(NULL), test) << std::endl;
}
}
我的输出看起来像
0...
1...
2...
3...
是不是difftime应该返回双打?
我认为它返回自1月1日,1970年 – Sunsetquest
有关POSIX系统子第二定时的秒数,考虑['clock_gettime()'](HTTP://酒吧。 opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html)(纳秒分辨率,现代,首选)或 ['gettimeofday()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday。 html)(微秒分辨率,不太现代,严格不赞成,但在'clock_gettime()'没有的Mac OS X上可用)。曾经有 ['ftime()'](http://pubs.opengroup.org/onlinepubs/009695399/functions/ftime.html)(毫秒分辨率,古代,不推荐) - 这是从POSIX 2001年(2004年)手册。 –