求高手帮忙写个C++代码

2024-12-22 02:32:09
推荐回答(1个)
回答1:

#include
#include

int main()
{
SYSTEMTIME stBeginTime;
SYSTEMTIME stEndTime;
ZeroMemory(&stBeginTime, sizeof(SYSTEMTIME));
ZeroMemory(&stEndTime, sizeof(SYSTEMTIME));

GetSystemTime(&stBeginTime);
/************************************************************************/
/*
Execute the main code
*/
/************************************************************************/

GetSystemTime(&stEndTime);

//the unit is second
DWORD dwSpareTime = (stEndTime.wHour - stBeginTime.wHour) * 60 * 60 * 1000;
dwSpareTime += (stEndTime.wMinute - stBeginTime.wMinute) * 60 * 1000;
dwSpareTime += (stEndTime.wSecond - stBeginTime.wSecond) * 1000;
dwSpareTime += stEndTime.wMilliseconds - stBeginTime.wMilliseconds;

cout < < "The Executing time is " < < dwSpareTime < < " Milliseconds " < < endl;
return 0;
}