C++代码在dev可以运行,在VS里却报错


#include <iostream>
#include <cstdlib>
using namespace std;

typedef struct node
{
    int data;
    pNODE next;
}NODE, * pNODE;

int main()
{
    pNODE head, p, q, t;
    int a, i, n;
    cin >> n;
    head = NULL;

    for (i = 1; i <= n; i++)
    {
        cin >> a;
        p = (pNODE)malloc(sizeof(NODE));
        p->data = a;
        p->next = NULL;
        if (head == NULL)
            head = p;
        else
            q->next = p;
        q = p;
    }
    t = head;
    while (t != NULL)
    {
        cout << t->data;
        t = t->next;
    }
    free(p);

    system("pause");
    return 0;
}

img

不能用pNode,用struct node *next

第9行:pNODE next; 修改为:struct node *next;

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632