(-) using the _sleep () function
Example: _sleep (200);//DELAY 200 ms
(ii) using the delay (int time) function (which requires its own implementation, not within the compiler)
[CPP]View PlainCopy
- @brief Program delay
- @param [in] msec: MS
- @remark
- @return void
- void delay_msec (int msec)
- {
- clock_t now = clock ();
- while (clock ()-now < msec);
- }
- @brief Program delay
- @param [In] sec: sec
- @remark
- @return void
- void Delay_sec (int sec)//
- {
- time_t start_time, Cur_time;
- Time (&start_time);
- Do
- {
- Time (&cur_time);
- } while ((Cur_time-start_time) < sec);
- }
For example, the delay of 2 seconds can be this: Delay_msec (2000); or delay_sec (2);
It should be noted that DELAY_MSEC has a higher time accuracy (up to 1 milliseconds, depending on the compiler definition) because it uses the clock ().
51943581
Several methods of delay processing for C + + program