_sleep() is not working in C++(_Slear()在C++中不起作用)
                            本文介绍了_Slear()在C++中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我试图编写简单的代码,但每当我调用函数_sleep()时,它都不起作用。我现在已经在两个不同的项目中尝试了它,每次我使用它时,它都会给我一个错误:1
‘_睡眠’:此函数或变量已被较新的库或操作系统功能取代。考虑改用睡眠疗法。有关详细信息,请参阅联机帮助。
我尝试了许多其他的东西,比如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;
}
推荐答案
睡眠()函数在不同的操作系统中是不同的,因为它是由操作系统库实现的。 如果您使用的是Windows,最好的方法是#Include the windows.h头文件, 然后,在您要使用睡眠功能的地方,将其用作睡眠(Time_In_Ms)。
#include <iostream>
#include <windows.h>
int main(){
std::cout << "A" << std::endl;
Sleep(3000);
std::cout << "B" << std::endl;
return 0;
}
                        这篇关于_Slear()在C++中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:_Slear()在C++中不起作用
				
        
 
            
        基础教程推荐
             猜你喜欢
        
	     - 如何通过C程序打开命令提示符Cmd 2022-12-09
 - 在 C++ 中计算滚动/移动平均值 2021-01-01
 - 如何检查GTK+3.0中的小部件类型? 2022-11-30
 - 我有静态或动态 boost 库吗? 2021-01-01
 - 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 - C++结构和函数声明。为什么它不能编译? 2022-11-07
 - 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
 - 如何在 C++ 中初始化静态常量成员? 2022-01-01
 - 这个宏可以转换成函数吗? 2022-01-01
 - 常量变量在标题中不起作用 2021-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				