在执行程序的过程中,可以根据不同的需求进行不同的延时操作,这里介绍两种方法,希望对大家有用!
1.Sleep(t);t的单位是毫秒;
但是在执行的过程中,整个程序会挂起来,停止执行;
2.timeGetTime()函数;
该函数以毫秒统计系统的时间,该时间为从系统开启算起的运行时间;
该函数在头文件<MMsystem.h>中;
程序如下:
- #include <stdafx.h>
- #include <Windows.h>
- #include <MMSystem.h>
- #include <iostream>
- using namespace std;
- #pragma comment(lib, "winmm.lib")
- void main(){
- DWORD timeBegin = timeGetTime();
- DWORD timeEnd = 0;
- do
- {
- timeEnd = timeGetTime();
- cout<< timeEnd <<endl;
- } while (timeEnd - timeBegin <= 100);
- getchar();
- }
更多的延时方法见博客:http://www.cppblog.com/sunraiing9/archive/2006/12/14/16415.html