How to make a pause (delay) in C++ for a certain number of milliseconds?
Hello! I'm writing a simple console program in C++ on Linux. I need the program to pause for several milliseconds (e.g., 500 ms) between text outputs or executing some actions.
I'm a beginner, and so far I've tried just `sleep(1)` from ``, but it only works for seconds. I need a delay in milliseconds. I've heard there's `usleep()`, but some sources say it's deprecated, and it's unclear how to use it correctly.
Here's an example of my code that doesn't work the way I want:
```cpp
#include
#include
int main() {
std::cout << "Start..." << std::endl;
sleep(0.5); // I want 500 ms, but sleep only accepts whole seconds
std::cout << "500 ms passed?" << std::endl;
return 0;
}
```
No answers yet.
Log in to leave an answer