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

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;
 }


Solution 1:[1]

Try this out:

this_thread::sleep_for(2s);

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

Solution 2:[2]

sleep is a POSIX (e.g. Linux, macOS) function.

The Windows "sleep" function is Sleep. Note the upper-case S in Sleep.

For a portable solution that is independent of OS then use this_thread::sleep_for instead.

Solution 3:[3]

If your OS is Windows, then use Sleep() instead of sleep() function prototype is in windows.h.

If you are using UNIX use nanosleep() or usleep() and the header name unistd.h.

Solution 4:[4]

Note: If you want to use <unisted.h> instead of <windows.h>.

Put this line in top your code:

unsigned int sleep(unsigned int seconds);

But in response of you cuestion you have to use Sleep() instead of sleep(), notice the uppercase of Sleep().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yahavi
Solution 2
Solution 3 Kalana
Solution 4