-
Pausing
No, this is not a "How do I keep my program from ending?" question. I don't even know if you can do this, but unlike system("PAUSE"); or cin.get(); and other various things to pause it, how do I get it to pause for a certain period of time? Like I want it to pause for 5 seconds and then do something else. Can I do this? If so, how?
-SirCrono6
-
Code:
#include <windows.h>
...
Sleep(5000); // sleep for 5 seconds
gg
-
Are there any other ways of doing this? I haven't really learned Windows programming yet. So is there a way to do this on a console?
-
That works very well for console:
Example
Code:
#include <windows.h>
int main()
{
Sleep(5000); // Make the program pause for 5 seconds
return 0;
}
-
Sleep() will work in a console if you're using a compiler with <windows.h>, even thought you're not creating a Windows GUI program.
Typically, most if not all compilers provide some form of Sleep or Delay function. Or if you want to stick to standard functionality then you can write your own using the functionality in the <time.h> or <ctime> header.
-
>So is there a way to do this on a console?
You can use Sleep in a console program.
>Are there any other ways of doing this?
You can either use a compiler extension (if one exists), or write your own hack that will likely be nonportable, nasty, and/or problematic in a multithreaded environment. Since the Win32 API Sleep function is standard among Windows systems, it would really be the best option.