how to make a time delay of a few seconds using C++


Hi,

I am using ubuntu linux.
How to make a time delay of a more than 30min using C++.
Last edited on
closed account (S6k9GNh0)
...What?

"How to make a time delay of a more than 30min using C++."

It sounds like you want a timer but I'm not exactly sure. :/
Last edited on
you can use sleep().

it take time in milliseconds.. so calculate how much you need to pass..
it will be around.. (1000 * 60 * 30)
closed account (S6k9GNh0)
I thought sleep only worked in Windows?
Sleep is the Windows version, the parameter is milli-seconds.
sleep is the Unix version, the parameter is seconds.
usleep() is the *nix equivalent, the argument is in micro-seconds (10-6).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS__) || defined(__TOS_WIN__)

  #include <windows.h>

  inline void delay( unsigned long ms )
    {
    Sleep( ms );
    }

#else  /* presume POSIX */

  #include <unistd.h>

  inline void delay( unsigned long ms )
    {
    usleep( ms * 1000 );
    }

#endif 

http://www.google.com/search?btnI=1&q=msdn+sleep
http://linux.die.net/man/3/usleep

Just to be complete. ;-)

Hi


Thanks friends......
Sorry for late reply

#include <ctime>

inline void mySleep(clock_t sec) // clock_t is a like typedef unsigned int clock_t. Use clock_t instead of integer in this context
{
clock_t start_time = clock();
clock_t end_time = sec * 1000 + start_time
while(clock() != end_time);
}
Last edited on
Topic archived. No new replies allowed.