关于visual studio的一个bug

本人初学链表,如有错误多多包涵

快马加鞭,这期只写一个问题。我好像在vs里面发现了一个bug

不管是vs2022还是vs2010都无法正常运行。关于cin、string、链表的问题

#include<iostream>
#include<string>
#include<stdlib.h>

//我先构建了2个结构体

struct q {
int P1;
string P2;
};

typedef struct node {
q data;//数据域
node* next;//指针域
}*linklist;

 

//首先要实现最基础的录入功能

//此处为函数的录入实现

void add(node* header) {
linklist current;
current = (linklist)malloc(sizeof(node));
if (current == NULL)
{
cerr << "!" << endl;
return;
}
current->next = NULL;
cin >> current->data.P1;//无法正常运行
cout << "一阶段成功" << endl;
cin >> current->data.P2;
cout << "二阶段成功" << endl;
}

 

//此处为主函数

int main() {
node* head;//定义首地址
head = (linklist)malloc(sizeof(node));
if (head == NULL)
{
cerr << "!" << endl;
return 0;
}
head->next = NULL;
add(head);
return 0;
}

//在vs2010和vs2022里 当读到cin >> current->data.P1时程序会自动中止并在数秒后退出,而codeblock中就不会存在此问题

posted @ 2022-07-04 18:39  天启A  阅读(60)  评论(0)    收藏  举报