doumalc++
February 19th, 2003, 09:34 AM
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.
Thanks.
|
Click to See Complete Forum and Search --> : Display current time in command prompt with update doumalc++ February 19th, 2003, 09:34 AM 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. doumalc++ February 21st, 2003, 05:47 AM bump... Still need an answer... mwilliamson February 21st, 2003, 09:37 AM using windows? int main() { while( true ) { SYSTEMTIME SystemTime; GetSystemTime( &SystemTime ); system("cls"); cout << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond; Sleep( 1000 ); }; return 0; } doumalc++ February 21st, 2003, 11:31 AM What library are you using? I know it is not <ctime>. stober February 21st, 2003, 01:05 PM 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. int main(int argc, char* argv[]) { while( true ) { SYSTEMTIME SystemTime; GetSystemTime( &SystemTime ); cout << "\r" << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond; Sleep( 1000 ); }; return 0; } mwilliamson February 21st, 2003, 04:02 PM 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. mwilliamson February 21st, 2003, 04:03 PM #include <windows.h> stober February 21st, 2003, 06:10 PM 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. that's easy to fix. just add some more spaces at the end int main(int argc, char* argv[]) { while( true ) { SYSTEMTIME SystemTime; GetSystemTime( &SystemTime ); cout << "\r" << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond << " "; Sleep( 1000 ); }; return 0; } mwilliamson February 21st, 2003, 06:44 PM thats a mess... lets just use cls :) stober February 21st, 2003, 06:48 PM 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. doumalc++ February 21st, 2003, 09:25 PM 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. :) codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |