ctime(部分)
clock_t // system typedef for clock() return (long in vc++6.0)
clock() // get system time
CLOCKS_PER_SEC // system time / sec
time(0);// include <cstdlib> srand(time(0)); rand();
//////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
//#include <cstring>
//#include <string>
#include <ctime> //ctime为调用clock()
int main()
{
using namespace std;
cout<<"enter delay time:(sec)"<<endl;
float secs;
cin>>secs;
cout<<"you must wait for "<<secs<<" secs"<<endl;
clock_t delay=secs; //clock_t为 typedef定义的类型别名
clock_t start=clock()/CLOCKS_PER_SEC; //CLOCKS_PER_SEC为 系统单位时间/每秒
cout<<"the start is: "<<start<<endl;
clock_t aa=start;
cout<<"the aa is: "<<aa<<endl;
int flag=0;
while((clock()/CLOCKS_PER_SEC+1-start)<delay)//控制结束,必须加1,让时间正常结束
{
if (secs==0)
;
else
{
if(flag==0) //第一秒内容输出
{
cout<<start-start+1<<"<--->"<<start<<"<--->";
cout<<"please wait(the first)"<<endl;
flag=1;
}
if((clock()/CLOCKS_PER_SEC-aa)==1) //第一秒后内容输出
{
cout<<clock()/CLOCKS_PER_SEC-start+1<<"<--->"<<"the \"clock()/CLOCKS_PER_SEC\" is "
<<clock()/CLOCKS_PER_SEC<<"<--->";
cout<<"please wait"<<endl;
aa=clock()/CLOCKS_PER_SEC;
}
}
}
//因为提前结束一秒所以结果加一秒
cout<<"at the last you wait:"<<clock()/CLOCKS_PER_SEC-start+1<<" secs"<<endl;
return 0;
}
// strcat strcpy strlen strcmp
//clock()
//CLOCKS_PER_SEC