award982 (83) Mar 20, 2010 at 12:49pm UTC
title ^
CManowar (17) Mar 20, 2010 at 12:49pm 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 Mar 20, 2010 at 12:49pm UTC
jloundy (161) Mar 20, 2010 at 12:49pm UTC
why wouldnt you just use the sleep() function?
but i do admire your copy and paste skills
Last edited on Mar 20, 2010 at 12:49pm UTC
helios (6064) Mar 20, 2010 at 12:49pm UTC
why wouldnt you just use the sleep() function?
There's no such thing.
Not in the standard, anyway.
kinley (9) Mar 20, 2010 at 12:49pm UTC
sleep() is part of unistd header file.
Just include
#include <unistd.h> to use that function.
Zhuge (634) Mar 20, 2010 at 12:49pm UTC
<unistd.h> is not part of the standard. :P
Hence,
There's no such thing.
Not in the standard, anyway.
cheesy (14) Mar 20, 2010 at 12:49pm UTC
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <windows.h>
int main()
{
cout << "Statement 1... " ;
Sleep(5000); // Milliseconds, just use (Number of Seconds)*1000 for seconds
cout << "Statement 2..." ;
cin.get():
return 0;
}
Works quite nicely.
AngelGithara23 (33) Mar 20, 2010 at 12:49pm UTC
*cough* on windows *cough*
By the way, thanks guys for the <ctime> info.
Last edited on Mar 20, 2010 at 12:49pm UTC
cheesy (14) Mar 20, 2010 at 12:49pm UTC
Yeah, sorry, not sure how to make this cross platform.
jloundy (161) Mar 20, 2010 at 12:49pm UTC
not every programmer is writing a cross platform application,
Last edited on Mar 20, 2010 at 12:49pm UTC
helios (6064) Mar 20, 2010 at 12:49pm UTC
Why should you assume they aren't if they don't give any indication of the opposite?
jloundy (161) Mar 20, 2010 at 12:49pm UTC
because you would think that a industrial programmer would already know the difference?
firedraco (2618) Mar 20, 2010 at 12:49pm UTC
Yeah, because the beginners forum is for industrial programmers >_>
jloundy (161) Mar 20, 2010 at 12:49pm UTC
@firedraco, thanks thats exactly what im tryin to say
This topic is archived - New replies not allowed.