我试图编写简单的代码,但是每当我调用该函数时,_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;
}
Run Code Online (Sandbox Code Playgroud)
Sleep() 函数在各种操作系统中是不同的,因为它是由操作系统库实现的。如果您使用的是 windows,最好的方法是 #include windows.h 头文件,然后在您想要使用 sleep 函数的地方将其用作Sleep(time_in_ms)。
#include <iostream>
#include <windows.h>
int main(){
std::cout << "A" << std::endl;
Sleep(3000);
std::cout << "B" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)