我时出现分段错误(核心已转储)getline(cin, node->name)
。
我通过str
在输入函数中声明一个字符串来修复,然后node->name = str
。但是跑到线上cin >> node->year
仍然击中了细分故障。
struct client
{
int code;
string name;
int year;
float maths, physics, chemistry;
struct client *next;
};
struct client* input()
{
struct client *node = (struct client *)malloc(sizeof(struct client));
cout << "Code: ";
cin >> node->code;
cout << "Name: ";
cin.ignore();
getline(cin, node->name);
cout << "Year: ";
cin >> node->year;
cout << "Maths, Physics, Chemistry: ";
cin >> node->maths >> node->physics >> node->chemistry;
node->next = …
Run Code Online (Sandbox Code Playgroud)