#include <iostream>
using namespace std;

#include <sctring>

struct student{  // 定义构造体
    int num;
    char name[10];
    float score[4];
};

int main(){
    student stud;  //定义变量
    stud.num = 123;   //成员的引用
    strcpy(stud.name , "xxx");   
}

注意在给 char name[10] 赋值时 不能 stud.name = "xxx"   ,不能把字符串赋给地址 

给char name[10]赋值可以 如上代码所示

也可以 cin>>stud.name;

或者 cin.getline ( stud.name , 80) ; 

 

相关文章:

  • 2022-02-02
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案