0

I've got the similar problem as python - loop at exact time intervals - the only difference is that I want to use C++.

So: how is it possible in C++ to make a loop in which every iteration would take a set amount of time, independently of the time of executing code in a loop?

// Example:
for (int i = 0; i < 100; i++)
{
    cout << "foo" << endl; // prints foo every, let's say, 1s
    bar(); // may take, let's say 1ms or 325ms (of course less than 1s)
}
CuSO4
  • 1
  • 1
  • You do it the same way as in the linked question. The only difference is that you do that in C++ and find [the appropriate standard library utilities](https://en.cppreference.com/w/cpp/header/chrono). – LogicStuff May 26 '19 at 09:47
  • The idea how to do that in c++ is merely the same as in the python style question you linked. Have a look at the facilities provided with standard c++: https://en.cppreference.com/w/cpp/thread – πάντα ῥεῖ May 26 '19 at 09:48

0 Answers0