2016-05-19 34 views
-2

我正在嘗試使計數器持續1分鐘,或以秒和分鐘顯示已用時間。C++中的分鐘計數器

這是我正在使用的代碼,但它沒有顯示時間,只是零。

char str[200]; 

double t = (double)getTickCount(); 

t = ((double)getTickCount() - t)/getTickFrequency(); 

sprintf(str, "%f detection time", t); 

putText(matCapturedImage, str, Point2f(100, 100), FONT_HERSHEY_PLAIN, 0.7, Scalar(0, 0, 255, 255));` 
+0

可以包含一個完整的例子嗎? – callyalater

+5

調用'getTickCount'兩次,它們之間沒有代碼可能會給你相同數量的刻度。 – NathanOliver

+0

我使用的代碼非常長,我只是放了相關部分 – tofi

回答

1

這可以幫助你

double t = (double)getTickCount(); 
double time=0; 
for(;;) 
{ 
    time = ((double)getTickCount() - t)/getTickFrequency(); 
    /*t is not updated but getTickCount() is*/ 
    if(time>=60.0) 
    { 
     t = (double)getTickCount(); 
     /*This resets t back to latest tick count and time back to zero*/ 
    } 
}