在C++,platform:windows中进行睡眠操作

Pum*_*kin 8 c++ windows sleep

我想以毫秒为单位执行上述操作.我更喜欢哪个库和函数调用?

TY.

seh*_*ehe 6

或者,如果您使用的是Visual Studio 2010(或其他c ++ 0x感知编译器)

#include <thread>
#include <chrono>

std::this_thread::sleep();

// or
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Run Code Online (Sandbox Code Playgroud)

使用较旧的编译器,您可以使用相关的Boost库获得相同的便利

毋庸置疑,这里的主要好处是可移植性以及将延迟参数转换为"人"单元的便利性.

  • 这在2010年不起作用.VS 2012,是的,但不是2010年. (2认同)
  • @OldPeculier这只是意味着这是现在普遍适用的答案,未来几年:) (2认同)

Bra*_*vic 5

您可以使用Win32 API中的Sleep功能.