Function to make program pause or sleep C++

802 views Asked by At

I am trying to find a way to pause or sleep my simple c++ program such as the time.sleep(x) in Python. Is there an equivalent in C++? An example of where I would want to use this is in here:

#include <iostream>

using namespace std;

int main() {
    for (int x = 0 ; x < 100 ; x++) {
        cout << 100 - x << " bottles of beer on the wall, "
             << 100 - x << " bottles of beer!\nTake one down pass it around "
             << 100 - (x + 1)  << " bottles of beer on the wall\n\n";
             //enter sleep here to pause before next output
    }
}

Thanks

1

There are 1 answers

1
nerox8664 On

You can use Sleep(ms) function from WinAPI or POSIX usleep(mcrsec)