C++延时用程序

#include <stdio.h>
#include <windows.h>
int main()
{
	printf("sleeping\n");
	Sleep(3*1000);
	printf("sleep end\n");
	return 0;
}

 

#include <iostream>
#include <ctime>
inline void delay(float);
int main()
{
	using namespace std;
	float secs;
	cin>>secs;
	cout<<"start\n";
	delay(secs);
	cout<<"end\n";
	return 0;
}
void delay(float secs)
{
	clock_t delay=secs*CLOCKS_PER_SEC;
	clock_t start=clock();
	while(clock()-start<delay);
}






posted @ 2014-08-19 09:52  Netop  阅读(509)  评论(0)    收藏  举报