_Slear()在C++中不起作用 [英] _sleep() is not working in C++

查看:72
本文介绍了_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++中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆