【求救】struct 中string 声明报错
请教大家一个问题:我在struct 中 用 string 定义成员 编译报错,希望大家帮我解决下,不胜感激!
代码:
#include <iostream>
#include <string>
using namespace std;
struct student
{
char name[20];
int age;
float salary;
string degree;
};
int main()
{
student zhangsan=
{
"Zhang",
28,
9000,
"Bachelor"
};
string teststring="Just for testing";
cout<<"Name:"<<zhangsan.name<<endl;
cout<<"Age: "<<zhangsan.age<<endl;
cout<<"Salary: "<<zhangsan.salary<<endl;
cout<<"Degree: "<<zhangsan.degree<<endl;
cout<<"The teststring is: "<<teststring<<endl;
return 0;
}
执行报错:error C2552: 'zhangsan' : non-aggregates cannot be initialized with initializer list
Error executing cl.exe.