Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delaying (pausing) C++ progam?

Status
Not open for further replies.

kook04

Programmer
Jun 26, 2001
58
US
Is it possible to place a "pause" in a C++ app? Basically, I want to execute an instruction, pause maybe 2 seconds, execute the next instruction. I know these capabilities exist in Java, how about C++?

Thanks...Kennedy ------
Kennedy Roberts
 
Sleep(2000);//sleep in milliseconds John Fill
1c.bmp


ivfmd@mail.md
 
Is there an include statement I need to use? I am getting an error.

Thanks ------
Kennedy Roberts
 
I'm sorry to keep bothering you, but I still get this error:

error C2065: 'sleep' : undeclared identifier

I have included <windows.h> according to you suggestion.


Thanks...Kennedy ------
Kennedy Roberts
 
Did you use sleep() or Sleep() - in Windows it needs to be capitalized.
 
Thank you. ------
Kennedy Roberts
 
You could also do a for loop such as

for (int i = 1; i<100000; i++)

or a similar while loop adjusting the number to the desired pause time
 
joeCpp-
That loop is not a good idea - it causes the program to use CPU cycles, while Sleep() actually avoids that by alerting the OS that the process/thread is going to be inactive.
 
Also the loop is always a bad idea in a multithreading environment. Even you know exactly how many steps are executed and know exactly how much time is required for one single step, in a multithreading environment you'll know never how much time will take all steps. John Fill
1c.bmp


ivfmd@mail.md
 
I use system(&quot;pause&quot;) with <iostream.h> and <iomanip.h>

it stops the program run, then hit the space bar to resume.

John Garrison


John Garrison
ccdp@socket.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top