Hello, I need a function like Sleep(time);
that pauses the program for X milliseconds, but in C++.
Please write which header to add and the function's signature. Thank you!
Hello, I need a function like Sleep(time);
that pauses the program for X milliseconds, but in C++.
Please write which header to add and the function's signature. Thank you!
#include "windows.h"
sleep(10);
for unix probably #include <unistd.h>
just google it...
There is no portable way to do this.
A portable way is to use Boost or Ace library. There is ACE_OS::sleep(); in ACE.
On unix, include #include <unistd.h>
... The call your interested in is usleep()... Which takes microseconds, so you should multiply your millisecond value by 1000 and pass the result to usleep()...
On Windows/Unix:
#ifdef _WIN32
#include <windows.h>
inline void sleep(unsigned pMilliseconds)
{
::Sleep(pMilliseconds);
}
#else
#include <unistd.h>
inline void sleep(unsigned pMilliseconds)
{
static const unsigned MilliToMicro = 1000;
::usleep(pmilliseconds * MilliToMicro);
}
#endif