为什么too many initializers
#include "iostream"#include "cstring"
using namespace std;
class student{
private:
char stunum[15];
char Name[20];
int math;
int Chinese;
int Total;
double Ave;
public:
student(char s[]="0",char N[]="0",int m=0,int C=0);
void input();
void print();
};
student::student(char s[],char N[],int m,int C){
strcpy(stunum,s);
strcpy(Name,N);
math=m;
Chinese=C;
Total=math+Chinese;
Ave=Total/2;
}
void student::input(){
cout<<"please input student number"<<endl;
cin.getline(stunum,15);
cout<<"please input name"<<endl;
cin.getline(Name,20);
cout<<"please input math"<<endl;
cin>>math;
cin.get();
cout<<"please input Chinese"<<endl;
cin>>Chinese;
cin.get();
Total=math+Chinese;
Ave=Total/2;
}
void student::print(){
cout<<"学号"<<stunum<<endl;
cout<<"姓名"<<Name<<endl;
cout<<"数学"<<math<<endl;
cout<<"语文"<<Chinese<<endl;
cout<<"总分"<<Total<<endl;
cout<<"平均分"<<Ave<<endl;
}
void main(){
int i,n;
student a[10]={{"1651030101","zhang",92,93},{"1651030102","wang",94,92},{"1651030103","li",95,92},{"1651030104","zhao",97,98},{"1651030105","qian",25,65},{"1651030106","sun",75,45},{"1651030107","hao",67,94}};
for(i=6;i<n;i++)
a[i].input();
for(i=0;i<n;i++)
a[i].print();
}
Desktop\2.cpp(53) : error C2078: too many initializers
[此贴子已经被作者于2017-9-1 17:39编辑过]