samedi 28 février 2015

Why won't _sleep(1000) compile in Xcode?

I have a program that is supposed to count down from 10 to 0, and every time it counts down it's supposed to wait one second then flush the output using cin.flush(). The professor demonstrated this in class and it worked perfectly, however, when I get home Xcode gives me an error saying that _sleep(1000) is the use of an undeclared identifier '_sleep' -- which is not supposed to be the case as I imported the special commands and it's only supposed to use _sleep in windows compilers.


In short, this needs to compile in both windows and mac compilers, which I am supposed to do by these compiler definitions. But for some reason Xcode keeps trying to tell me it's wrong.



#ifdef GPP
#include <unistd.h>
#else
#include <cstdlib>
#endif


int main()
{
for (int timer = 10; timer >= 0; timer--)
{
cout << timer;
cout.flush();

//compiler functions
#ifdef GPP
Sleep(1); //One second to sleep on GPP compilers
#else
_sleep(1000);//On windows 1000ms sleep time
#endif

cout << '\r';
}
}

Aucun commentaire:

Enregistrer un commentaire