dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Dec 4, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


A pause function

Question:
I cannot figure out a pause function for C++. Our books are very generic...can you please help?

Answer:
To pause for a given amount of time, you will need to interface with your environment. But you didn't indicate what OS your program was running under.

To pause in Windows, you can call the Sleep function, which will put the current thread to "sleep" for the specified number of milliseconds.

If you want to write your own for systems such as DOS, your pause routine will need to sit in a loop until the specified time has elapsed. Something like this:

#include 
#include 

void Pause(int nSeconds)
{
   time_t begin, current;

   // Get start time
   time(&begin);
   // Loop until time has elapsed
   do {
      // Get current time
      time(¤t);
   } while (difftime(current, begin) < nSeconds);
}
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date