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.
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; }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
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); }
p.s. What the alphabet would look like without q and r.