Sleep()函数windows 8 c++; 我尝试用C++编写Windows 8操作系统上的睡眠()函数。到目前为止,我还没有找到任何具体的例子

Sleep()函数windows 8 c++; 我尝试用C++编写Windows 8操作系统上的睡眠()函数。到目前为止,我还没有找到任何具体的例子,c++,windows-8,header,undefined,sleep,C++,Windows 8,Header,Undefined,Sleep,下面是我的标题,虽然我得到了“标识符”Sleep“未定义”。我可以从Synchapi.h中找到函数SleepConditionVariableCS()和SleepConditionVariableSRW(),但不能找到Sleep() 是否有人在Windows 8操作系统上使用过Sleep(),或者知道我找不到该函数的原因?您使用的是C++11吗?如果您是,您可以使用: #include <thread> template< class Rep, class Period >

下面是我的标题
,虽然我得到了“标识符”Sleep“未定义”。我可以从Synchapi.h中找到函数SleepConditionVariableCS()和SleepConditionVariableSRW(),但不能找到Sleep()


是否有人在Windows 8操作系统上使用过Sleep(),或者知道我找不到该函数的原因?

您使用的是C++11吗?如果您是,您可以使用:

#include <thread>
template< class Rep, class Period >
void sleep_for( const std::chrono::duration<Rep,Period>& sleep_duration );
#包括
模板
无效睡眠时间(const std::chrono::duration&sleep_duration);
更新 Sleep()函数仅适用于桌面应用程序。您是否正在构建一个以前称为Metro的应用程序?还是应用商店应用程序? 有关一些解决方法,请参阅本文:


你不应该直接包括Synchapi.h。改为包含Windows.h

#include <Windows.h>

int main()
{
  Sleep(1000);
  return 0;
}
#包括
int main()
{
睡眠(1000);
返回0;
}
ah这就是为什么(我正在构建一个Metro应用程序)。另一种选择看起来相当复杂。