即时显示时间

 1 #include <iostream>
 2 #include <iomanip>
 3 #include <ctime>
 4 #include <windows.h>
 5 using namespace std;
 6 int main()
 7 {
 8 time_t ti = time(NULL);
 9 struct tm* timer = localtime(&ti);
10 while(1)
11 {
12 cout << setfill('0') << setw(2) << timer->tm_hour << ":" <<setw(2) << timer->tm_min << ":" << setw(2) << timer->tm_sec << "
";
13 Sleep(1000);//睡眠一秒钟
14 if(++timer->tm_sec >= 60)//
15 {
16      timer->tm_sec = 0;
17      if(++timer->tm_min >= 60)//
18 {
19      timer->tm_min = 0;
20      if(++timer->tm_hour >= 24)//
21         timer->tm_hour = 0;
22 }
23 }
24 }
25 return 0;
26 }
View Code
原文地址:https://www.cnblogs.com/bmyell1234/p/4602868.html