#include<string.h>
typedef struct
{
int number;
char name[10]="smith";
char gender[5];
int age;
} Student;
不要在结构定义的时候初始化。这个功能支持需要C++11,或者GNU++11,你看看你的编译器是否支持吧
一般这么写
typedef struct
{
int number;
char name[10];
char gender[5];
int age;
} Student;
Student s;
strcpy(s.name,"smith");
在编译属性里面添加-std=c++11,或者是结构体里面的成员变量(数组)不要初始化。
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!