c++ - Delay execution 1 second -
so trying program simple tick-based game. write in c++ on linux machine. code below illustrates i'm trying accomplish.
for (unsigned int = 0; < 40; ++i) { functioncall(); sleep(1000); // wait 1 second next function call }
well, doesn't work. seems sleeps 40 seconds, prints out whatever result function call.
i tried creating new function called delay, , looked this:
void delay(int seconds) { time_t start, current; time(&start); { time(¤t); } while ((current - start) < seconds); }
same result here. anybody?
to reiterate on has been stated others concrete example:
assuming you're using std::cout
output, should call std::cout.flush();
right before sleep command. see this ms knowledgebase article.
Comments
Post a Comment