Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - error: 'sleep' was not declared in this scope

Tags:

c++

windows

I started learning programming a few days ago, and today i tried writing a countdown program, but everytime i try to start a program i get error: 'sleep' was not declared in this scope. I searched everywhere for solution but i didn't find it.

#include <iostream>
#include <windows.h>
#include <cstdlib>

using namespace std;

int main()
 {

 for(int i=30; i>=0; i--)

    {
        sleep(1000)
        system("cls")
        cout << i;
    }

    return 0;
 }
like image 884
guacamoleboi Avatar asked Jan 30 '26 04:01

guacamoleboi


1 Answers

Try this out:

this_thread::sleep_for(2s);

Source: https://en.cppreference.com/w/cpp/thread/sleep_for

like image 105
yahavi Avatar answered Feb 01 '26 18:02

yahavi