帮忙看一下,这个程序为什么不显示第一个元素的fullname?
#include<iostream>using namespace std;
const int SLEN=30;
struct student
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[],int n);
void display1(student st);
void display2(const student* ps);
void display3(student pa[],int n);
int main()
{
cout<<"Enter class size: ";
int class_size;
cin>>class_size;
while(cin.get()!='\n')
continue;
student* ptr_stu=new student[class_size];
int entered=getinfo(ptr_stu,class_size);
for(int i=0;i<entered;i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu,entered);
delete [] ptr_stu;
return 0;
}
int getinfo(student pa[],int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"Enter element # "<<i+1<<":\n";
cout<<"Enter student's fullname:";
while(cin.get()!='\n')
continue;
cin.getline(pa[i].fullname,SLEN);
cin.getline(pa[i].fullname,SLEN);
cout<<"Enter student's hobby:";
cin.getline(pa[i].hobby,SLEN);
cout<<"Enter student's ooplevel:";
cin>>pa[i].ooplevel;
}
return i;
}
void display1(student st)
{
cout<<"============================\n";
cout<<"student's fullname="<<st.fullname<<endl;
cout<<"student's hobby="<<st.hobby<<endl;
cout<<"student's ooplevel="<<st.ooplevel<<endl;
cout<<"============================\n";
}
void display2(const student* ps)
{
cout<<"============================\n";
cout<<"student's fullname="<<ps->fullname<<endl;
cout<<"student's hobby="<<ps->hobby<<endl;
cout<<"student's ooplevel="<<ps->ooplevel<<endl;
cout<<"============================\n";
}
void display3(student pa[],int n)
{
cout<<"============================\n";
for(int i=0;i<n;i++)
{
cout<<"student's fullname="<<pa[i].fullname<<endl;
cout<<"student's hobby="<<pa[i].hobby<<endl;
cout<<"student's ooplevel="<<pa[i].ooplevel<<endl;
}
cout<<"============================\n";
}