文件 I/O 问题

文件 I/O 问题:
(1)对不存在的或者错误的文件进行操作吗?
(2)文件以不正确的方式打开吗?
(3)文件结束判断不正确吗?
(4)没有正确地关闭文件吗?

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdlib.h>
 4 #include <time.h>
 5 
 6 #define ARRAY_SIZE 15
 7 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 8 
 9 using namespace std;
10 
11 //显示数组
12 void put_array(int x[],int size) {
13     for(int i=0;i<size;i++)
14         cout<<x[i]<<" ";
15     cout<<endl;
16 }
17 
18 //产生指定范围的整数随机数
19 int getrand(int min,int max) {
20     int m;
21     m=(max-min);
22     m=min+double(rand())/RAND_MAX*m ;
23     return m;
24 }
25 //在main()函数中测试max_element()和 min_element()算法
26 int main(int argc, char** argv) {
27 
28     //声明变量和数组
29     int i;
30     int x[ARRAY_SIZE];
31 
32     //用1到100的随机数初始化数组,并显示
33     srand( (unsigned)time( NULL ) );
34     for (i=0;i<ARRAY_SIZE;i++) {
35         x[i]=getrand(1,100);
36     }
37     cout<<"x[]:";
38     put_array(x,ARRAY_SIZE);
39 
40     //对数组x使用max_element()算法,并显示
41     int *pMax=max_element(x,x+ARRAY_SIZE);
42     cout<<"pMax    ="<<pMax<<endl;
43     cout<<"Location="<<(pMax-x)<<endl;
44     cout<<"*pMax   ="<<(*pMax)<<endl;
45 
46     //对数组x使用min_element()算法,并显示
47     int *pMin=min_element(x,x+ARRAY_SIZE);
48     cout<<"pMin    ="<<pMin<<endl;
49     cout<<"Location="<<(pMin-x)<<endl;
50     cout<<"*pMin   ="<<(*pMin)<<endl;
51     
52         return 0;
53 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9418322.html