how to have a timer

i am making something for people who don't know how to make c++ code (saying text) so what is the code for a 10 second delay till the screen closes like
 
return 0;
C++ does not have a built-in delay function. Delay functions are operating system dependent.

For example, Windows has the Sleep() function:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx

1
2
3
4
5
#include <chrono>
#include <thread>

void sleep_for( unsigned int millisecs )
{ std::this_thread::sleep_for( std::chrono::milliseconds(millisecs) ) ; }

http://coliru.stacked-crooked.com/a/ffe810e97ea43223
An easy way to create a delay could be to just run a for-loop incrementing your loop control variable to a very high number.

Something like this....

1
2
3
4
5
6
7

//stuff

for(long int i = 0; i < 100000; i++)

//stuff
Topic archived. No new replies allowed.