//******************file operator********************
//******************read in file*********************
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int a,max=-9999,i;
ifstream fin("f1.dat",ios::in);
if(!fin)
{
cerr<<"open error!"<<endl;
exit(1);
}else
{
cout<<"open correctly"<<endl;
}
while(fin>>a)
{
if(a>max)
{
max=a;
}
}
fin.close();
cout<<"the maximum in file is :"<<max<<endl;
return 0;
}
文件内容
运行结果