I would like to know how I display the current type in the command prompt so that it updates itself to show the changing time.
Thanks.
Printable View
I would like to know how I display the current type in the command prompt so that it updates itself to show the changing time.
Thanks.
bump...
Still need an answer...
using windows?
Code:int main()
{
while( true )
{
SYSTEMTIME SystemTime;
GetSystemTime( &SystemTime );
system("cls");
cout << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond;
Sleep( 1000 );
};
return 0;
}
What library are you using?
I know it is not <ctime>.
Using mwilliamson's idea, here is another method. This one just moves the cursor back to the beginning of the current line without erasing the entire window.
Code:int main(int argc, char* argv[])
{
while( true )
{
SYSTEMTIME SystemTime;
GetSystemTime( &SystemTime );
cout << "\r" << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond;
Sleep( 1000 );
};
return 0;
}
If you do that, when you switch from 12:59.59 to 1:00.00 then you will not overwrite all of the characters making your output 1:00.009.
#include <windows.h>
that's easy to fix. just add some more spaces at the endQuote:
Originally posted by mwilliamson
If you do that, when you switch from 12:59.59 to 1:00.00 then you will not overwrite all of the characters making your output 1:00.009.
Code:int main(int argc, char* argv[])
{
while( true )
{
SYSTEMTIME SystemTime;
GetSystemTime( &SystemTime );
cout << "\r" << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond << " ";
Sleep( 1000 );
};
return 0;
}
thats a mess... lets just use cls :)
if you use cls you erase the entire screen -- there may be other stuff on the screen that you don't want erased. it would also cause a flicker affect.
Thanks guys!
I was trying to time the execution of a program using constant time update. That won't work in the DOS console however.
I will simply display the time before and after execution of the code. :)