C++: sleep() obsolete... so what's its successor?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

mussavcom

Thread Starter
Joined
Mar 28, 2004
Messages
51
I have a lot of sleep(1) function calls in my program.
sleep(unsigned int) is obsolete, according to the Borland C++ compiler. It gives me the following warning:

Warning W8053 ar1.cpp 26: 'sleep(unsigned int)' is obsolete in function main()

So, OK, it's just a warning, so I keep using sleep(). But now I have too many of these function calls, and I get this message after all the warnings:

Error E2228 ar1.cpp 357: Too many error or warning messages in function DE()

(DE is the last function out of about 6 so far, but later it'll be about 40-50 functions.)

So now it won't compile due to the error of having too many warnings.

Is there a newer function I can use to pause the program for a certain amount of seconds?

Thanks,
Michael
 
Joined
Nov 24, 2002
Messages
2,438
It means call the function and pass into it the value of the delay you want in milliseconds in the form of a data type DWORD, which is a macro substitution for an "unsigned long" 32bit integer value. You could declare a variable of this type and give it the value of delay you require, or a value dependant on calculation for that matter then just call the Sleep() function and pass that variable to it.

DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds
Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold!

try something like that.

Not sure of the '#include's you will need off the top of my head, #include<winbase.h> springs to mind but coderitr would be better advising that if you don't know yourself. :)
 
Joined
Oct 12, 2003
Messages
3,015
#include <windows.h>

Will get you everything you need. Thanks for the excellent follow-up explanation AlbertB. I copied my post from the MSDN library article on the function without realizing that I may have neede to provide more.

You can call the function without a separate variable declaration ( saving a whopping 4 bytes of memory :D ) by the following:

Sleep( 1000 ); // sleep for 1 second
 

mussavcom

Thread Starter
Joined
Mar 28, 2004
Messages
51
Thanks, coderitr and AlbertB. Now I can actually pause for half a second, amazing... :)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top