Is there a reliable, cross-platform way to pause a program for a set amount of time? The getch() function will wait for user input, but I would like to be able to pause for say 3 seconds. If a for loop is used like so:

#include <iostream>
using namespace std;

int main()
{
     for(i = 0, i < 10000, i++)
     {
     }
     return 0;
}

There will be no garuntee that on a machine running a quad-core the code will always pause for 3 seconds.

Is there an easy way to time using <ctime>? I saw AncientDragons' post about subtracting the system start time from the current time and that could be used, but is there an easier way?

I suppose you could use the time functions in time.h

time_t t1, t2;
t1 = time(0);
t2 = t1
while( (t2 - t1) < 1) // one second
  t2 = time(0);

You might also check the Boost time functions

commented: Interesting indeed! =) +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.