今天弄了个c++版计时器,
这是代码:
#include <bits/stdc++.h>
#include<iostream>
#include<windows.h>
#define /*蓝色*/blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE);
using namespace std;
class Clock{
public:
Clock(short h=0,short m=0,short s=0):h(h),m(m),s(s){
}
void displayTime();
private:
short h;
short m;
short s;
};void Clock::displayTime(){
while(true){
cout<<h<<':'<<m<<':'<<s<<" ";
Sleep(1000);
cout<<'\r';
if(!(s=++s%60))
if(!(m=++m%60))
h=++h%24;
}
}
int main()
{
blue
cout<<" 计时器"<<endl;
Clock A(0,0,0);
A.displayTime();
return 0;
}