定时器类(C++实现)
#include <ctime>
class CTimer
{
public:
clock_t Begin;
clock_t End;
double elapTicks;
double elapMilli, elapSeconds, elapMinutes;
CTimer () {this->Begin = clock () * CLK_TCK;}
void Stop () { this->End = clock () * CLK_TCK; getTimes ();}
void getTimes ()
{
this->elapTicks = this->End – this->Begin;
this->elapMilli = this->elapTicks/1000;
this->elapSeconds = this->elapMilli/1000;
this->elapMinutes = this->elapSeconds/60;
}
};
/** EXAMPLE USAGE **/
#include <iostream>
using namespace std;
int main ()
{
CTimer myTimer;
char input;
cin >> input;
myTimer.Stop ();
cout << myTimer.elapSeconds << endl;
cin.get ();
return EXIT_SUCCESS;
}
:oops: 表示看不懂。话说这个定时器用来做什么的。
测试头像。。哇咔咔
另外,为什么百度百科里面写的是用clock ()除以 CLK_TCK?
CLK_TCK是一秒的滴答数目?不懂。。。
哇噢,windows 8木有给我识别出来:)
YM用win8滴呀