Sleep是Windows API函数,当然Mac用不了,可以用 usleep nanosleep 等代替
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Going to sleep...\n");
usleep(3000000); // 暂停进程 3 秒钟
printf("Wake up!\n");
return 0;
}
#include <stdio.h>
#include <time.h>
int main() {
printf("Going to sleep...\n");
struct timespec ts = { .tv_sec = 3, .tv_nsec = 0 }; // 挂起 3 秒钟
nanosleep(&ts, NULL);
printf("Wake up!\n");
return 0;
}