Jun 29, 2009 at 12:10pm UTC
You first need to include this library:
Then make a function, like this one:
1 2 3 4 5 6
void breakTime( int seconds)
{
clock_t temp;
temp = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < temp) {}
}
A test run:
1 2 3 4 5 6 7 8 9 10 11 12
#include ".h" // our function and ctime include is here & iostream.h
int main()
{
for (int i=10; i!=0; i--) {
cout << i << endl;
breakTime(1); // wait 1 second
}
cout << "Fire!" << endl;
return 0;
}
Last edited on Jun 29, 2009 at 12:13pm UTC
Jun 29, 2009 at 5:46pm UTC
why wouldnt you just use the sleep() function?
but i do admire your copy and paste skills
Last edited on Jun 29, 2009 at 5:47pm UTC
Jun 29, 2009 at 11:02pm UTC
sleep() is part of unistd header file.
Just include
#include <unistd.h> to use that function.
Jun 30, 2009 at 6:11pm UTC
*cough* on windows *cough*
By the way, thanks guys for the <ctime> info.
Last edited on Jun 30, 2009 at 6:16pm UTC
Jun 30, 2009 at 6:27pm UTC
Yeah, sorry, not sure how to make this cross platform.
Jun 30, 2009 at 10:46pm UTC
not every programmer is writing a cross platform application,
Last edited on Jun 30, 2009 at 10:48pm UTC
Jun 30, 2009 at 11:00pm UTC
Why should you assume they aren't if they don't give any indication of the opposite?
Jul 1, 2009 at 3:00pm UTC
because you would think that a industrial programmer would already know the difference?
Jul 1, 2009 at 4:27pm UTC
Yeah, because the beginners forum is for industrial programmers >_>
Jul 1, 2009 at 5:37pm UTC
@firedraco, thanks thats exactly what im tryin to say