Sunday, July 12, 2009

How can i make a c++ program pause for a set number of seconds, say 5?

Im trying to find code that will let me pause a program for a set amount of time. ideally i would like to use the system time or a c++ function specifically for delaying a program if there is one.

How can i make a c++ program pause for a set number of seconds, say 5?
This is platform specific. On Windows, you can use the Sleep(milliseconds) functions. I'm not familiar with Unix or Linux().
Reply:You can include time.h in your program and then put in something like this:





float delay;





delay=clock()+5*CLK_TCK;


while (clock()%26lt;delay)


{


}
Reply:I recommend using the sleep command.





sleep(5);


would make the program pause for 5 seconds.
Reply:for windows, sleep(seconds);

snow of june

No comments:

Post a Comment