我正在使用控制檯模式下使用Visual C++/CLR的項目。 如何以微秒獲得系統時鐘? 我想顯示hours:minutes:seconds:microseconds
如何在C++中以微秒獲取系統時鐘?
下面的程序運作良好,但不與其他平臺兼容:
#include <stdio.h>
#include <sys/time.h>
int main()
{
struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday(&tv, &tz);
tm=localtime(&tv.tv_sec);
printf(" %d:%02d:%02d %ld \n", tm->tm_hour, tm->tm_min,tm->tm_sec, tv.tv_usec);
return 0;
}
這是一個國際性的地方,所以請使用英語。 –