background image

1.推荐用 Sleep();
 

1.推荐用 Sleep();

  

 MS VC++可以用 MFC 的 Sleep 函数,参数是毫秒。

  

 包含在头文件<windows.h>里

 

/*#include<iostream>

#include<windows.h>
using namespace std;

void main   ()
{

Sleep(1000);     //延时 1 秒
cout<<"adsd"<<endl;
Sleep(10000);       // 注意 S 大写
cout<<"123"<<endl;

}   */

  

 2.delay();

  

 delay 函数要自己写,编译器里没有。

 

#include <time.h>

void delay(int sec)
{
time_t start_time, cur_time; // 变量声明
time(&start_time);
do { time(&cur_time);
} while((cur_time - start_time) < sec );
}

  

 然后就可以直接调用了

  

 如:

 

#include<iostream.h>

#include <time.h>
void delay(int sec)