在编写函数时,要进行反复的考查,并且自问: “我打算做哪些假定?”

在编写函数时,要进行反复的考查,并且自问: “我打算做哪些假定?”

一旦确定了的假定,就要使用断言对假定进行检查。

 

 1 #include <iostream>
 2 #include <time.h>
 3 #include <sys/types.h>
 4 #include <sys/stat.h>
 5 #include <stdio.h>
 6 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 7 
 8 using namespace std;
 9 int main(int argc, char** argv) {
10     struct stat buf;
11     int result;
12 
13     //获得c:\Windows\Calc.exe文件的状态信息
14     result =stat( "c:\\windows\\Calc.exe", &buf );
15 
16     //显示Calc.exe文件的状态信息
17    if( result != 0 )
18        perror( "Problem getting information" );
19     else
20     {
21         cout<<"Size of the file in bytes:"<<buf.st_size<<endl;
22         cout<<"Drive number of the disk containing the file :";
23         cout<<char(buf.st_dev + 'A')<<endl;
24         cout<<"Time of creation of the file:"<<ctime(&buf.st_ctime);
25         cout<<"Time of last access of the file:"<<ctime(&buf.st_atime);
26         cout<<"Time of last modification of the file:"<<ctime(&buf.st_mtime);
27    }
28     return 0;
29 }

 

posted @ 2018-08-03 13:29  borter  阅读(118)  评论(0编辑  收藏  举报