使程序暂停或休眠C ++的功能

时间:2016-12-21 15:13:19

标签: c++ for-loop time sleep pause

我正试图找到一种方法来暂停或睡眠我的简单c ++程序,例如Python中的time.sleep(x)。 C ++中有等价的吗?我想要使​​用它的一个例子是:

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

由于

1 个答案:

答案 0 :(得分:0)

您可以使用WinAPI或POSIX Sleep(ms)

中的usleep(mcrsec)功能
相关问题