我正在使用eclipse而且我正在构建一个简单的程序,但是我得到一个错误,说函数sleep无法解析
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
printf("ciao");
sleep(20);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道我是否需要其他库或其他东西.MinGW应该正确安装,所以我不知道
该sleep()函数由POSIX定义,而不是由C++标准定义.
如果您使用的是类Unix系统,则需要
#include <unistd.h>
Run Code Online (Sandbox Code Playgroud)
如果不是,则该sleep()功能可能甚至不可用.
哦,混合cout << ...,printf()可能不是一个好主意,你不需要#include <conio.h>.