#include <stdio.h>
#include <conio.h> //kbhit()/_kbhit()
#include <Windows.h> //Sleep(ms)
int main()
{
int hour = 0, min = 0, sec = 0;
int cnt = 0;
printf("按任意键停止计时\n");
while(!_kbhit()) //任意键退出循环(结束计时)
{
hour = cnt / 3600; //获取计时小时数
min = cnt / 60; //获取计时分钟数
sec = cnt % 60; //获取计时秒数
printf(" %02d:%02d:%02d\r", hour, min, sec);
Sleep(1000); //1s延时
cnt++;
}
printf("\n程序退出\n");
return 0;
}
c++计时器代码
最新推荐文章于 2024-05-15 23:27:45 发布