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(&current);     }     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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -