我正在研究一个项目,我需要比整个秒(即time())更精细的粒度。我正在浏览opengroup.org,我注意到有数据结构与成员tv_usec和tv_nsec。[milli |微| |纳秒]粒度使用tv_usec或tv_nsec
#include <stdio.h>
#include <time.h>
int main (void) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
printf("%lis %lins\n", ts.tv_sec, ts.tv_nsec);
return 0;
}
test.cpp(5) : error C2079: 'ts' uses undefined struct 'main::timespec'
test.cpp(6) : error C2065: 'CLOCK_REALTIME' : undeclared identifier
test.cpp(6) : error C3861: 'clock_gettime': identifier not found
是否有一种简单的方法通过使用标准库获得高精度时间值?我实际上并不需要很高的准确度,但我确实需要增加相对时间。
你正在使用什么操作系统? – 2012-07-20 22:57:39
在这里编译...这是POSIX系统..你使用Windows或其他东西? – 2012-07-20 23:03:34
是的,不幸的是我使用Windows ... – Zak 2012-07-21 01:51:22