Home c++ how to make a timer on C++

how to make a timer on C++

Author

Date

Category

Making the game Snake, studying the POP C++, and there is code:

while (true) {
  snake.move ();
  SLEEP (150); // delay in 150 milliseconds
}

How to make this “Sleep ()”?
OS – Linux


Answer 1, Authority 100%

https://stackoverflow.com/questions/4184468/sleep-for-milliseconds

Tools of the standard library.

# include & lt; chrono & gt;
#Include & lt; Thread & GT;
Std :: This_Thread :: Sleep_for (STD :: Chrono :: MilliseConds (X));

Answer 2, Authority 25%

In Linux there is a USLEEP ready function that “shifts” the flow to a given number of microseconds. To use it requires to connect

# include & lt; unistd.h & gt;

You can use it so

usleep (150,000);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions