我有一个控制台应用程序,旨在只在 Windows 上运行。它写在C++。有什么办法可以等待60秒 (and 显示剩余时间在屏幕上)然后继续代码流?
我尝试了互联网上的不同解决方案,但没有一个有效。它们要么不起作用,要么无法正确显示时间。
//Please note that this is Windows specific code
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
int counter = 60; //amount of seconds
Sleep(1000);
while (counter >= 1)
{
cout << "\rTime remaining: " << counter << flush;
Sleep(1000);
counter--;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)