CString str,str1;
//获取程序运行时间
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)
// Sleep(500);
AfxMessageBox("do something...");
long t2=GetTickCount();//程序段结束后取得系统运行时间(ms)
str.Format("time:%dms",t2-t1);//前后之差即 程序运行时间
AfxMessageBox(str);
//获取系统运行时间
long t=GetTickCount();
str1.Format("系统已运行 %d时",t/3600000);
str=str1;
t%=3600000;
str1.Format("%d分",t/60000);
str+=str1;
t%=60000;
str1.Format("%d秒",t/1000);
str+=str1;
AfxMessageBox(str); 黑色头发:http://heisetoufa.iteye.com/
本文介绍了一种使用C++中的GetTickCount函数来测量程序运行时间的方法,并展示了如何格式化输出运行时间,包括毫秒、秒、分钟及小时。

1118

被折叠的 条评论
为什么被折叠?



