# include<iostream.h>
# include<fstream.h>
# include<stdlib.h>
# include<string.h>
/* struct student
{
char name[30];
int number ,score;
};*/
void main()
{
/*char fileName[30];
cout<<"请输入文件名:"<<endl;
cin>>fileName;
fstream stu(fileName,ios::out|ios::in|ios::binary);
/*if(!stu)
{
cerr<<"文件打开失败!"<<endl;
abort();
}
student st;
student * ps=&st;
int counter1=0;
int counter2=0;
double total=0;
do
{
cout<<"请输入学号,姓名,分数\n?";
cin>>ps->number>>ps->name>>ps->score;
if(cin.get()==EOF)
break;
counter1++;
total+=ps->score;
stu.write((char*)ps,sizeof(student));
}while(1);
cout<<"平均分为:"<<total/counter1<<endl;
stu.seekg(0);
for(int i=0;i<counter1;i++)
{
stu.read((char*)ps,sizeof(student));
cout<<"学号为:"<<ps->number<<ends<<"姓名为:"<<ps->name<<ends<<"分数为:"<<ps->score<<endl;
}
char name2[30];
do
{
cout<<"请输入你想查询学生的姓名(noname结束):"<<endl;
cin>>name2;
/*if(!strcmp(name2,"noname"))
{
cout<<"退出查询!"<<endl;
return;
}
else
{
stu.seekg(0);
for(int i=0;i<counter1;i++)
{
stu.read((char*)ps,sizeof(student));
if(!(strcmp(ps->name,name2)))
{
cout<<"学号为:"<<ps->number<<ends<<"姓名为:"<<ps->name<<ends<<"分数为:"<<ps->score<<endl;
break;
}
else
counter2++;
}
if(counter2==counter1)
cout<<"没有你想查询的学生!"<<endl;
}*/
}while(1);
/* for(int pass=1;pass<counter1;pass++)
{
for(j=0;j<counter1-pass;j++)
{
if(pt[i]->score>pt[i+1]->scor)
{
temp=pt[i]->score;
pt[i]->score=pt[i+1]->scor;
pt[i+1]->scor=temp;
work=0;
}
}
if(work)break;
}
}
for(i=0;i<counter1;i++)
{
stu.seekg(0);
stu.read((char*)pt[i],sizeof(student));
}*/
}
各位帮忙看看这个程序的运行错误:运行到cin时不能输入。