首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

新手,syntax error '{'

2013-04-09 
新手求助,syntax error '{'#include iostreamusing namespace stdstruct Student{long idch

新手求助,syntax error '{'
#include <iostream>

using namespace std;

struct Student
{
long id;
char gender;
int age;
int money;
};

Student InitializeStudent(long id, char gender, int age, int money, int manualinput=0);
void DisplayStudent(Student currentstudent);

int main()
{
const int Array_Size=5;
Student array[Array_Size];
array[0]=InitializeStudent(9413599, 'M', 25, 10001,0);
array[1]=InitializeStudent(9513622, 'M', 22, 500,0);
array[2]=InitializeStudent(9613812, 'F', 20, 30,0);
array[3]=InitializeStudent(9713964, 'F', 18, 66000,0);
array[4]=InitializeStudent(0, ' ', 0, 0,1);
for (int i=0; i!=Array_Size; i++)
{
DisplayStudent(array[i]);
}
return 0;
}

Student InitializeStudent(long id, char gender, int age, int money, int manualinput)
{
Student newstudent;
if (manualinput==0)
{
newstudent = {id,gender,age,money};//LINE 37
}
else
{
cout<<"Please enter your student id: ";
cin >> newstudent.id;
cout<<"Gender (M/F): ";
cin>>newstudent.gender;
cout<<"Age: ";
cin>>newstudent.age;
cout<<"The amount of money in your own: ";
cin>>newstudent.money;
}
return newstudent;
}


以下是error information. 我用的IDE是visual studio.
全都发生在LINE 37

Error1error C2059: syntax error : '{'
Error2error C2143: syntax error : missing ';' before '{'
Error3error C2143: syntax error : missing ';' before '}'
Error4IntelliSense: expected an expression

请问我是哪里错了呢? 欢迎任何评论~ struct c++
[解决办法]
大括号形式的只能在初始化的时候使用,你是先定义再赋值这样是不行的
可以把定义和return全都放到分支内
[解决办法]
这个你只能依次的赋值了
newstudent.age = 10;
。。。

热点排行