How does one "pause" a program in C++ on Win 32, and what libraries must be included?
The sleep() method in the C programming language allows you to wait for just a current thread for a set amount of time. The sleep() function will sleep the present executable for the time specified by the thread.
The sleep() function in C returns 0 if the requested time has elapsed. Due to signal transmission sleep() returns the unslept quantity, a difference between the requested time to sleep() and the time it actually slept in seconds.
Answer: The header for sleep is “unistd. h” for LINUX/UNIX Operating system and “Windows. h” for the Windows Operating system.
h> Sleep(number of milliseconds); Or if you want to pause your program while waiting for another program, use WaitForSingleObject.
#include <windows.h> Sleep(number of milliseconds);
Or if you want to pause your program while waiting for another program, use WaitForSingleObject.
In C++11, you can do this with standard library facilities:
#include <chrono> #include <thread> std::this_thread::sleep_for(std::chrono::milliseconds(x));
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