I know the POSIX sleep(x)
function makes the program sleep for x seconds. Is there a function to make the program sleep for x milliseconds in C++?
In C++11, you can do this with standard library facilities:
#include <chrono> #include <thread>
std::this_thread::sleep_for(std::chrono::milliseconds(x));
Clear and readable, no more need to guess at what units the sleep()
function takes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With