我试图编写简单的代码,但每当我调用函数 _sleep()
它都不起作用。我现在在两个不同的项目中尝试过它,每次使用它时,它都会给我一个错误,上面写着:1
‘_sleep’:此函数或变量已被更新的库或操作系统功能取代。考虑改用睡眠。详细信息请参见在线帮助。
我尝试了很多其他的东西,比如 Sleep()
, sleep()
以及一堆其他没有用的随机垃圾。如果有另一个命令会暂停控制台一段时间,我可以更改我想要的方式,并且不会弹出一些丑陋的东西,例如 "Press any key to continue..."
,或者修复我的命令,请让我知道!
代码
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int rouletteGen();
int main()
{
//--------
//| Idea |
//--------
//cout << box 1 << box 2 << endl;
int wheel, a, b, c, time, cA, cB, cC;
roulette:
while (a >= 1)
{
cout << " _|_" << endl;
cout << " \|/" << endl;
cout << "_______ _______ _______" << endl;
cout << "| | | | | |" << endl;
cout << "| "<< cA <<" | | "<< cB<<" | | "<< cC<<" |" << endl;
cout << "| | | | | |" << endl;
cout << "_______ _______ _______" << endl;
_sleep(250);
while (b >= 1)
{
cout << "_|_" << endl;
cout << "\|/" << endl;
_sleep(250);
while (c >= 15)
{
}
}
}
}
int rouletteGen()
{
int dice;
srand(time(NULL));
dice = rand() % 3;
dice = dice + 1;
return dice;
}
原文由 iiZ 发布,翻译遵循 CC BY-SA 4.0 许可协议
Sleep() 函数在各种操作系统中是不同的,因为它是由操作系统库实现的。如果您使用的是 Windows,最好的方法是 #include windows.h 头文件,然后在您想使用睡眠功能的地方将其用作 Sleep(time_in_ms) 。