0

Why Sleep(); not recognize in c++?

#include <iostream> #include <unistd.h> using namespace std; int main() { int fake,second=10; fake=second; for (;;) { cout<<second << endl; if (second == fake) { --second ; fake=fake-1; } sleep(1) ; if (second==0) break; } } This program work on my PC and it's exactly the same

5th Apr 2017, 5:09 PM
Lefteris Vamvakas
Lefteris Vamvakas - avatar
3 odpowiedzi
+ 9
Because it's OS dependant I think.
5th Apr 2017, 6:03 PM
Karl T.
Karl T. - avatar
+ 3
Helioform is right, it is indeed OS dependent. The "unistd.h" header will be present on Unix systems, but not Windows. Apparently SoloLearn's online compiler uses Windows (an odd choice, to say the least). For a cross-platform sleep function, try this (I think Windows' uses milliseconds): #ifdef _WIN32 #include <windows.h> #define sleep(x) Sleep(x * 1000); #else #include <unistd.h> #endif I've verified this as working on here.
5th Apr 2017, 9:23 PM
Squidy
Squidy - avatar
0
ok I will try thanks guys 😀
5th Apr 2017, 10:05 PM
Lefteris Vamvakas
Lefteris Vamvakas - avatar