不仅要检查输入参数的有效性,还要检查通过其它途径进入函数体内 的变量的有效性...

不仅要检查输入参数的有效性,还要检查通过其它途径进入函数体内 的变量的有效性,例如全局变量、文件句柄等。

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 #include<conio.h>
 5 #include <time.h>
 6 
 7 using namespace std;
 8 //定义时间延迟函数
 9 void Dtime(double dt) {
10     time_t current_time;
11     time_t start_time;
12 
13     // 得到开始时间
14     time(&start_time);
15     //延迟处理
16     do 
17     {
18       time(&current_time);
19     } 
20     while (difftime(current_time,start_time)<dt);
21 }
22 
23 //控制台函数显示
24 void cputs_show(int n) {
25     time_t current_time;
26     char *timep;
27     cputs("Show time with cputs\n");
28 
29     for(int i=0;i<5;i++) {
30         time(&current_time);
31         timep=ctime(&current_time);
32         cputs(timep);
33         Dtime(n);
34     }
35 }
36 
37 //cout对象显示
38 void cout_show(int n) {
39     time_t current_time;
40     char *timep;
41     cout<<"Show time with cout"<<endl;
42 
43     for(int i=0;i<5;i++) {
44         time(&current_time);
45         timep=ctime(&current_time);
46         cout<<timep;
47         Dtime(n);
48     }
49 }
50 
51 //main()函数的定义
52 int main(int argc, char** argv) {
53    cputs_show(1);
54     cout_show(1);
55     return 0;
56 }

 

转载于:https://www.cnblogs.com/borter/p/9413623.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值