void Wait(double Duration)
{
clock_t End;
End = clock() + (Duration*CLOCKS_PER_SEC);
while (clock() < End)
{
// This loop just stalls the program.
}
}
我的函数有一半的时间可以完美运行,但它偶尔会在程序被调用之前停止。例如,采用以下代码段:
cout << "This is\n";
Wait(2.5)
cout << "a test!";
您希望第一行立即出现,第二行在 2.5 秒后出现,但有时 ALL 会在 2.5 秒后出现。这是怎么回事?