use*_*171 5 c++ time mingw timer
使用minGW的g ++.exe编译一些Linux C++代码时遇到了一些困难.具体来说,它无法理解此代码:
struct timespec now;
clock_gettime(CLOCK_REALTIME,&now);
Run Code Online (Sandbox Code Playgroud)
我添加了必要的头文件
#include <ctime>
Run Code Online (Sandbox Code Playgroud)
编译错误是:
error: aggregate 'special_time2()::timespec now' has incomplete type and cannot be defined
error: 'CLOCK_REALTIME' was not declared in this scope
error: 'clock_gettime' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会这样,并知道潜在的解决方法?
clock_gettime 不是标准的C或C++函数,因此无法保证它在非POSIX系统上可用.
如果您正在编写现代C++,那么您可以使用该std::chrono库进行高精度计时.
如果你坚持使用2011年之前的库,那么你唯一的选择是time(),通常只有一秒的精度,或任何特定于平台的替代品.不幸的是,我不太了解MinGW对你的帮助.