I'm currently having trouble finding out a way to run simulations automatically every 3 seconds. I've been working on a small simulation console game (At them moment) and I haven't been able to find any solution. All I'm trying to manage is a way to run a loop every 3 seconds and output the results on the screen -- I have the majority of the program written already I just need to input this specific function. Help would be appreciated.
Does this loop need to run in the background (i.e. you can do other stuff while this loop is running), or are you okay with stopping your game for 3 seconds while you wait for it to run again?
If it's the latter, you can use the clock() function in <ctime> to idly loop for 3 seconds:
If you need this to run in the background, then use std::thread like Dput mentioned above. (But note that you'll need a fairly recent compiler that supports C++11 features in order to use it)
I am actually looking for a way to do that too but I suppose I don't have that specific library. Thank you for leading me in that direction though.
I'll just have to get a more recent version of c++ I guess?
The C++ threading functions are only supported on C++11 so you will need a compiler that is updated to run that. A quick search will tell you if what you are using can support it.
Otherwise I recommend you look up the Boost library for threading if you want your time-based function running parallel to everything else.
For GCC, you'll also need to enable C++11 features using either -std=gnu++11, -std=c++11, -std=gnu++0x, or -std=c++0x (at least one of those should work for you).
(Or, if you're using an IDE, find an option to enable C++11 features.)