Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function sleep could not be resolved

Tags:

c++

sleep

eclipse

I'm using eclipse and I'm building a simple program, but I get an error saying function sleep could not be resolved

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

I don't know if I need other libraries or something else. MinGW should be installed properly, so I have no idea

like image 985
andrea Avatar asked Apr 30 '26 09:04

andrea


1 Answers

The sleep() function is defined by POSIX, not by the C++ standard.

If you're on a Unix-like system, you need

#include <unistd.h>

If you're not, then the sleep() function might not even be available.

Oh, and mixing cout << ... and printf() is probably not a good idea, and you don't need the #include <conio.h>.

like image 197
Keith Thompson Avatar answered May 03 '26 10:05

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!