#include<iostream>
#include<string>
#include<stdio.h>
using namespace std; //结构体
typedef struct student {
int score;
string id;
string name;
}stu,*stu1;
int main()
{
/*stu s;
s.name = "weilifeng";
s.id = "201743303117";
s.score = 60;
cout << s.name << " " << s.id << " " << s.score << endl;*/
//上面注释的代码可以运行
//我想通过指针申请内存空间 ,然后再进行赋值,不报错,但运行不了
//我大概觉得可能是越界的问题。但是问题出在哪里不知道 求解答
stu1 a;
a = (stu1)malloc(sizeof(stu));
if (a == NULL)
{
cout << "error";
exit(0);
}
a->score = 60;
a->id = "201743303117";
a->name = "weilifeng";
cout << a->name << " " << a->id << " " << a->score << endl;
}
通过断点,调试出来的问题 出现在 这句
a->id = "201743303117";
下面是报错的反馈
0x00007FFB517113D6 (vcruntime140d.dll)处(位于 Project1.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF 时发生访问冲突。