求指教,为什么内存不能为read
#include<iostream>
#include "malloc.h"
using namespace std;
#define F 0
#define T 1
typedef struct{
string name;
int classid;
int age;
}Student;
typedef struct Node{
Student stu;
struct Node *next;
}Node,*LinkList;
void initlist(LinkList *H){
*H=(LinkList)malloc(sizeof(LinkList));
(*H)->next=NULL;
}//初始化单链表
void createlist(LinkList H){
Node *n,*r;
r=H;
string name;
int age,classid,flag;
cout<<"请输入姓名: ";
cin>>name;
cout<<"\n请输入年龄: ";
cin>>age;
cout<<"\n请输入学号: ";
cin>>classid;
cout<<"\n请输入 1 继续 0 退出\n";
while(flag){
n=(Node*)malloc(sizeof(Node));
n->stu.name=name;
n->stu.age=age;
n->stu.classid=classid;
r->next=n;
r=n;
r->next=NULL;
}
}//创建单链表
int main(){
LinkList *h;
initlist(h);
createlist(*h);
Node *s=*h;
while(s!=NULL){
cout<<s->stu.name<<" "<<s->stu.age<<" "<<s->stu.classid<<endl;
s=s->next;
}
}
学号输入之后就会出现内存不能为read。。。。
[解决办法]
可能缓冲区溢出.
char name[16];cin>>name