我试图编写简单的代码,但是每当我调用该函数_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;
}
由于操作系统库正在实现Sleep()函数,因此在各种操作系统中它都不同。如果使用Windows,最好的方法是#include windows.h头文件,然后在要使用睡眠功能的地方将其用作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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句