我为C ++ 11找到的最简单的方法是:
您的包括:
#include
#include
您的代码(这是睡眠1000毫秒的示例):
std::chrono::duration timespan(1000);
std::this_thread::sleep_for(timespan);
持续时间可以配置为以下任意一种:
std::chrono::nanoseconds duration*signed integer type of at least 64 bits*/, std::nano>
std::chrono::microseconds duration*signed integer type of at least 55 bits*/, std::micro>
std::chrono::milliseconds duration*signed integer type of at least 45 bits*/, std::milli>
std::chrono::seconds duration*signed integer type of at least 35 bits*/, std::ratio<1>>
std::chrono::minutes duration*signed integer type of at least 29 bits*/, std::ratio<60>>
std::chrono::hours duration*signed integer type of at least 23 bits*/, std::ratio<3600>>