Skip to content
Sign upLog in

Delay for c++

Profile icon

Does anyone know a compatible delay function for c++? I would like to use it to make the computer slow down, and make it easier for calculations. Thanks!

You are viewing a single comment. View All
Profile icon


You can wrap it inside a function.

#include <iostream> #include <string> #include <unistd.h> // (50 * 1000) = 50 milliseconds #define DEFAULT_PRINT_DELAY (50 * 1000) using namespace std; void special_print(string message, int delay=DEFAULT_PRINT_DELAY) { for (char c: message) { cout << c << std::flush; // flush it so you see it printed immediately usleep(delay); } cout << "\n"; } int main() { cout << "Message: "; special_print("testtesttesttesttesttesttest"); }