#include <iostream>
#include <ctime>
using namespace std;
class Time{
int hour;
int min;
int sec;
public:
Time()
{
time_t tt=time(NULL);
tm *t=localtime(&tt);
hour=t->tm_hour;
min=t->tm_min;
sec=t->tm_sec;
}
void show()
{
cout << '\r';
if(hour<10) cout << 0;
cout << hour << ':';
if(min<10) cout << 0;
cout << min << ':';
if(sec<10) cout << 0;
cout << sec << flush;
}
void tick()
{
long t=time(NULL);
while(time(NULL)==t);
if(++sec>=60)
{
sec=0;
if(++min>=60)
{
min=0;
if(++hour>=24)
hour=0;
}
}
}
void run()
{
for(;;)
{
tick();
show();
}
}
};
int main()
{
Time t;
t.run();
}
c++源代码:时钟(获取系统当前时间)
最新推荐文章于 2024-04-21 09:59:13 发布