c++ - _sleep() 函数不工作

标签 c++

<分区>

我得到错误:

'_sleep': This function or variable has been superceded by newer library or operating system functionality. Consider using Sleep instead. See online help for details.

你们能告诉我是什么库导致了这个错误吗?

代码:

// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
using std::cout;
using std::cin;
using std::string;
using std::getline;

void ltr()    //gives a random letter
{
    srand(time(NULL));    //gives a differant pattern every time
    char letter;
    letter = rand() % 27 + 64;         //assigns a random letter in ascii code to a char (resulting in a random letter)
    cout << "The letter is " << letter << "\n";
}

void timer()
{
    cout << "You got 1.5 minutes to finish\n";
    for (int i = 90; i > 0; i--)
    {
        if (i % 5 == 0)
            cout << i << "\n";
        _sleep(1000);
    }
    cout << "DING DONG!!! DING DONG!!! Time's up!!!\n";
}

void table()
{
    int plr, ctr;
    string lst[5][20];           //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
    cin >> plr >> ctr;       //parameters for later
    cin.ignore();                  //To avoid the "getline" reading the last input
    for (int x = 0; x<plr; x++)       //the player changes only after the previus player finishes
    {
        timer();
        for (int i = 0; i<ctr; i++)        //changing catagory
        {
            getline(cin, lst[x][i]);
        }
        system("cls");
        cout << "Next player\n";
    }
    for (int x = 0; x<plr; x++)                   //this part (the whole "for" loop) is for confirming
    {
        cout << "Player number " << x + 1 << ": ";
        for (int i = 0; i<ctr; i++)
        {
            cout << lst[x][i] << "    ";
        }
        cout << "\n";
    }
    _sleep(5000);
}

int points()        //points per round
{
    int a, b, c, sum;
    cout << "How many sections only you got?\n";          //worth 15 points
    cin >> a;
    cout << "How many words only you got?\n";       //worth 10 points
    cin >> b;
    cout << "How many words you and another person got?\n";    //worth 5 points
    cin >> c;
    sum = a * 15 + b * 10 + c * 5;
    return sum;           //Note: It doesn't matter how many sections there are.
}

int act()
{
    int Points;
    ltr();
    table();
    Points = points();
    cout << "You have earned " << Points << " this round\n\n";
    return Points;
}

int main()
{
    int Points;
    cout << "Starting in five seconds\n";
    _sleep(5000);
    Points = act();
    for (;;)          //inf loop
    {
        int ph;
        cout << "Press 1 to continue or anything else to stop\n";
        cin >> ph;
        if (ph == 1)
        {
            Points += act();
        }
        else
        {
            break;
        }
    }
    cout << "You have earned a total of " << Points << " great job!";
    _sleep(5000);       //time to read the last text
    return 0;
}

/* To do list:
  *Convert to arduino
  *Make timer work in background of of table
  *Check if words in the table (for differant players) are the same and give points accordingly
  *Check if words are actual words (connect an online dictonary?)
  *Make interface? (if possible and I have time to learn how)
  *Think of what to do with Hardwear
  *Comment rest of the code
*/

最佳答案

要使用 Sleep() 函数,您需要

#include <windows.h>

关于c++ - _sleep() 函数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41779426/

相关文章:

c++ - Windows WriteFileGather 函数将最后一个错误设置为 ERROR_INVALID_PARAMETER

c++ - 用于测试目的 : which floating point (IEEE754 32b) numbers are "special"?

c++ - 如何最好地处理类中的一堆引用

c++ - 来自片段着色器中 GL_TEXTURE_1D 的样本

c++ - 下标对 const 的引用

c++ - 指数生成器有时会给出 "weird"结果

c++ - 控制台无响应?

c++ - 为什么函数名不能与返回名类型相同?

c++ - 如何从 Adob​​e AIR 应用程序获取 HDC 或屏幕截图?

c++ - 声明和定义之间 const 限定符的使用不一致