#include
using namespace std;
typedef struct stu
{
char sno[5];
float math,chinese,english,avg,sum;
}student;
int main()
{
student s[4];
for(int i=0;i<4;++i)
{
sprintf(s[i].sno,"%d",i);
s[i].math=i;
s[i].chinese=i;
s[i].english=i;
s[i].avg=i;
s[i].sum=i;
}
FILE *fp=fopen("1.txt","w");
if(fp)
{
for(int i=0;i<4;++i)
fwrite(&s[i],sizeof(student),1,fp); //写入结构数据,用于测试
fclose(fp);
}
fp=fopen("1.txt","r");
int count=0;
if(fp)
{
char *buf=new char[sizeof(student)];
while(fread(buf,sizeof(student),1,fp)!=NULL) //一个个结构读
++count;//读入一个结构,加1
fclose(fp);
}
//输出文件中的结构数
cout<<"count="<
}