![]() |
#2
zhaobuzhule2014-03-23 20:36
|
#include<iostream>
#include<cstdlib>
#include<fstream>
using namespace std;
void zuidazhi(ifstream &in);
void zuixiaozhi(ifstream &in);
int main()
{
ifstream in;
in.open("int.txt");
if(in.fail())
{
cout<<"流建立失败!"<<endl;
exit(1);
}
zuidazhi(in);
zuixiaozhi(in);
in.close();
return 0;
}
void zuidazhi(ifstream &in)
{
int max,next;
in>>max;
while(in>>next)
{
if(next>max)
max=next;
}
cout<<"int文件中最大值为"<<max<<endl;
return;
}
void zuixiaozhi(ifstream &in)
{
int min,next;
in>>min;
cout<<min<<endl;
while(in>>next)
{
if(next<min)
min=next;
}
cout<<"int文件中最小值是"<<min<<endl;
return;
}
txt文件内容是23 123 13 1244 123 1321 1223 233 21 2 1 23 3333