参考代码如下:
#include<iostream>
#include <fstream>
using namespace std;
int main()
{
int a[20];
ofstream myfile1("f1.txt", ios::out);
cout << "请输入10个数值(用空格隔开)" << endl;
for (int i = 0; i < 10; i++)
{
cin >> a[i];
myfile1 << a[i] << endl;
}
myfile1.close();
ifstream myfile2("f1.txt", ios::in);
if (!myfile2.is_open())
{
cout << "f1.txt打开失败!" << endl;
return 0;
}
int b[20];
cout << "所有成绩:";
int nMax = 0;
for (int i = 0; i < 10; i++)
{
myfile2 >> b[i];
cout << b[i] << " ";
if (nMax < b[i])
nMax = b[i];
}
myfile2.close();
cout << endl << "最高成绩:" << nMax << endl;
return 0;
}