how do i do a 1 second delay between perofming commands?
Printable View
how do i do a 1 second delay between perofming commands?
when i use it within a loop, it waits for 1second * number of times to loop iterates and then it prints out all the numbers at once.
I was writing a test program (countdown clock) so the loop is a s such
for(int a=10;a>=0;a--)
{
cout<<a<<endl;
Sleep(1000);
}
You can't directly output a number using "cout". You'll have to convert it to a char first.
Try this:
PHP Code:char buffer[10];
for(int a=10;a>=0;a--)
{
itoa(a, buffer,10);
cout<<buffer<<endl;
Sleep(1000);
}
That's not true. You can output numbers with cout.
:)
You can output anything with cout as long as it overloads the "<<" operator.
Z.
That's kind of the whole POINT of the streams using the << operator ;)Quote:
Originally posted by abdul
Ahhh, never tried and knew that. I have always converted a number to a string before outputting it using cout...Now I know...
Now you know why I love stringstreams :p