Is there a function like Sleep(time); that pauses the program for X milliseconds, but in C++?
Which header should I add and what is the function\'s sign
The simplest way I found for C++ 11 was this:
Your includes:
#include
#include
Your code (this is an example for sleep 1000 millisecond):
std::chrono::duration timespan(1000);
std::this_thread::sleep_for(timespan);
The duration could be configured to any of the following:
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>>