+ 1
How to add a time delay in c++?
I want to add a time delay b/w two commands in c++. I'll prefer a function with its header file,than a loop. I've tried many but none worked.
7 Antworten
+ 9
first way: use sleep function
second way:
include <ctime>
paste this function:
int delay(int milliseconds){
clock_t goal = milliseconds + clock();
while(goal>clock());
return 1;
}
then call delay function ex:
delay(2*1000);
cout << "Cow please gimme a milk :(";
+ 4
@Martin
I found one that works.
Because it does not use sleep
It just does not show the countdown.
https://code.sololearn.com/ckWiLzHgnyJ2/?ref=app
+ 2
@Martin
You are right while the code is a functional timer the SL compiler does not do it justice.
+ 1
I have used sleep function, including <windows.h>.
But it didn't worked. The output came at once. Someone suggested me delay(),usleep()....blah blah