Hi.
What functions are there in Visual C++ which is similar to delay(int milliseconds) of Turbo C++?
I am making a simple DOS EXE using Visual C++ and needs to delay/wait for a few seconds between the functions.
Thanks in advance.
Printable View
Hi.
What functions are there in Visual C++ which is similar to delay(int milliseconds) of Turbo C++?
I am making a simple DOS EXE using Visual C++ and needs to delay/wait for a few seconds between the functions.
Thanks in advance.
Code:#include <time.h>
void wait(unsigned timeout)
{
timeout += std::clock();
while(std::clock() < timeout) continue;
}
The Sleep function suspends the execution of the thread.
#include <windows.h>
Sleep(1000); // wait 1 second
That's really a last resort since it doesn't care about other threads/processes and probably isn't as efficient as a compiler specific function that does the same thing. Since the best option is a nonportable function, you should wrap your own function around it and use that, then you only have to make one change when you port the programCode:#include <time.h>
void wait(unsigned timeout)
{
timeout += std::clock();
while(std::clock() < timeout) continue;
}
Code:// Tc++
#include <dos.h>
void wait(long msecs)
{
delay(msecs);
}
// Vc++
#include <windows.h>
void wait(long msecs)
{
Sleep(msecs);
}