很简单啊
#include <stdio.h>
#incluude <fstream>
#include <iostream>
#include<string>
using namespace std;
void find(ofstream &fp, char * szKey)
{
ifstream in("grades.txt");
if(!in)
{
cerr << "some errors happened";
return -1;
}
string str;
while(getline(in, str))
{
if(-1!=str.find_first_of(szKey))
{
cout << str << endl;
break;
}
}
return 0;
}
void append(ofstream &fp)
{
char szNo[16];
char szName[10];
float fEnglish, fMath, fComputer;
//输入中间用空格间隔
scanf("%s %s %f %f %f\n",szNo, szName, &fEnglish, &fMath, &fComputer);
fp << szNo << szName << fEnglish << fMath << fComputer<<endl;
}
int main()
{
ofstream resulttxt;
resulttxt.open("grades.txt", ios_base::out | ios_base::app);
resulttxt << "
学号||" << "姓名||" << "英语成绩||" << "数学成绩||" << "计算机成绩"<<endl;
for(int i = 0; i < 10; i++)
{
append(resulttxt);
}
resulttxt.close();
return 0;
}
本回答被网友采纳