|
-
February 19th, 2003, 10:34 AM
#1
Display current time in command prompt with update
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.
-
February 21st, 2003, 06:47 AM
#2
bump...
Still need an answer...
-
February 21st, 2003, 10:37 AM
#3
using windows?
Code:
int main()
{
while( true )
{
SYSTEMTIME SystemTime;
GetSystemTime( &SystemTime );
system("cls");
cout << SystemTime.wHour << ":" << SystemTime.wMinute << "." << SystemTime.wSecond;
Sleep( 1000 );
};
return 0;
}
-
February 21st, 2003, 12:31 PM
#4
What library are you using?
I know it is not <ctime>.
-
February 21st, 2003, 02:05 PM
#5
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;
}
-
February 21st, 2003, 05:02 PM
#6
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.
-
February 21st, 2003, 05:03 PM
#7
-
February 21st, 2003, 07:10 PM
#8
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
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;
}
-
February 21st, 2003, 07:44 PM
#9
thats a mess... lets just use cls
-
February 21st, 2003, 07:48 PM
#10
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.
-
February 21st, 2003, 10:25 PM
#11
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|