#include <iostream>#include<Windows.h>using namespacestd;classti{intH//hours intM//minutes intS//seconds Public: void Set(intHourintMinintSec//Passing timer values{h=hour; M=min; S=sec; }; voidTick ()//Timing Bounce{Sleep ( +);//execution hangs for 1000 milliseconds, that is, wait one second before proceedings--; if(S <0) {s= -; M--; if(M <0) {m= -; H--; } } }; voidShow ()//Show remaining time { if(H <Ten) {cout<<0; } cout<< h<<":"; if(M <Ten) cout<<0; cout<< m<<":"; if(S <Ten) cout<<0; cout<<s; }; voidrun () { while(H | | m | | s)//keep running until full 0{tick (); System ("CLS"); Show (); } cout<<"Time out!"<<Endl; }}; intMain () {TI t; T.Set(0,2,0);//2 minutes Countdown .T.run ();}
Wait a second method,
(1) Sleep (1000); wait 1000 milliseconds
(2) #include <time.h>
time_t t=time (NULL); Gets the number of seconds that have been counted since January 1, 1970
while (Time (NULL) ==t); Until the number of seconds is different, that's 1 seconds.
Programming: Countdown Timer