#include<iostream>
#include<fstream>
using namespace std;
struct staff
{
string NAME;
string COUNTRY;
int NUMBER;
};
int main()
{
staff Team[3] =
{
"西班牙","美东" ,5,
"葡萄牙","希罗",4,
"法国","格子",3
}, Team1;
ofstream Outfile_1("staff.dat");
if (!Outfile_1)
{
cerr << "open staff.dat error!" << endl;
exit(1);
}
ofstream Outfile("staff.dat", ios::out);
fstream iofile("staff.dat", ios::in | ios::out | ios::binary);
if (!iofile)
{
cerr << "open error!" << endl;
abort();
}
int i, m, num;
cout << "Three staff:" << endl;
for (i = 0; i < 3; i++)
{
cout << Team[i].NAME << " " << Team[i].COUNTRY << " " << Team[i].NUMBER <<endl;
iofile.write((char*)&Team[i], sizeof(Team[i]));
}
bool find;
cout << "输入球队进球数得到相应信息,输出0则程序结束。";
cin >> num;
while (num)
{
find = false;
iofile.seekg(0, ios::beg);
for (i = 0; i < 3; i++)
{
iofile.read((char*)&Team[i], sizeof(Team[i]));
if (num <= Team[i].NUMBER)
{
cout << Team[i].NAME << " " << Team[i].COUNTRY << " " << Team[i].NUMBER <<endl;
find = true;
}
}
if (!find)
cout << "未找到对应信息。" << endl;
cout << "输入球队进球数得到相应信息,输出0则程序结束。";
cin >> num;
}
iofile.close();
return 0;
}