功能使程序暂停或睡眠C

Function to make program pause or sleep C++

本文关键字:程序暂停 功能      更新时间:2023-10-16

我正在尝试找到一种方法来暂停或睡觉我的简单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 wallnn";
             //enter sleep here to pause before next output
    }
}

谢谢

您可以从Winapi或Posix usleep(mcrsec)

中使用Sleep(ms)功能