-
timer
hello, i know this has been posted many times, and i have read all of the other threads.
what i want to do is count down in seconds from 10 to 1 and display it on screen. (just as an example)
But, i dont want to use the sleep function, because its not portable.
i have recently read somewhere how to do it. But i cant remember where! :rolleyes:
please help.
-
This thread covers most all your options.
gg
-
Another thread that may help
-
looks like i will have to use sleep() then, as for the portable solution kills the computer.
but when i put the code:
Code:
#include <iostream.h>
#include <windows.h>
int main()
{
for(int c=0;c<10;c++)
{
cout<<c;
Sleep(10);
}
return 0;
}
it just waits for 10 miliseconds an then writes 123456789 all at the same time, instead of waiting 10 miliseconds each time through the loop?
-
10 milliseconds is one hundreth of a second, not a long time! Try a larger value like a thousand(one second).
-
yes i know, if i put 1000 in it waits 10 seconds and then prints 123456789 all at the same time. i dont know why?
-
>and then prints 123456789 all at the same time
Flush the buffer after each character:
-
cheers, works great.
what exactly does 'flush' do?
does it just empty the contents of a variable?
-
>what exactly does 'flush' do?
It forces the output to be written to a device (in this case the screen) immediately. Otherwise your program would wait to flush the buffer until it was full, or something else caused a flush (such as endl) for performance reasons.
-
something I've been wondering: how do you know how big the buffer is (just curious)