菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
249
0

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

原创
05/13 14:22
阅读数 25942

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

 

 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 }

 

发表评论

0/200
249 点赞
0 评论
收藏