need help delaying a loop output c++

Status
Not open for further replies.

jcortes

Fully Optimized
Messages
1,909
hey i was making a program but i want it to loop some text but have a delay after each line of about 1 second. any ideas how i can accomplish this.
 
I think theres a sleep(...) function in windows.h . It takes the required delay time as the parameter
 
You can also use this:

#include <iostream>
#include <ctime>

using namespace std;

int main()
{

clock_t delay;
clock_t start;

// your loop here (eg: while, for, etc.)
delay = 0.3 * CLOCKS_PER_SEC; // replace 0.3 with your delay in seconds
start = clock();
while(clock() - start < delay)
;
// end your loop here

return 0;
}
 
Status
Not open for further replies.
Back
Top Bottom