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
3 ответов
+ 9
Because it's OS dependant I think.
+ 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.
0
ok I will try
thanks guys 😀