首页 > 解决方案 > 调试和编译类依赖于 VS Code 的文件

问题描述

如何调试在 VSCode 上实现类的代码?除了如下所示的方法,还有其他编译调试的方法吗?主文件代码如下。

#include<iostream>
#include "Node.h"
using namespace std;
int main(){
    Node test;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        test.append(&test.head,a[i]);
    }  
    test.printList(test.head);
    test.insertAfter(test.head->next->next,9); 
    test.printList(test.head);

}

类实现文件如下

#include<iostream>
#include "Node.h"
using namespace std;

Node::Node(){
    head=NULL;
}

void Node::append(Node** head_ref,int newData){
    Node* newNode= new Node;
    newNode->data=newData;
    if(*head_ref==NULL){
        newNode->prev=NULL;
        newNode->next=NULL;
        *head_ref=newNode;
        return;
    }
    Node *n=*head_ref;
    while(n->next!=NULL)
        n=n->next;
    newNode->next=n->next;
    newNode->prev=n;
    n->next=newNode;

}
void Node::insertAfter(Node* prev_node,int newData){
    Node* newNode= new Node;
    newNode->data=newData;
    prev_node->next->prev=newNode;
    newNode->next=prev_node->next;
    newNode->prev=prev_node;
    prev_node->next=newNode;

}


void Node::printList(Node*n){
    if(n==NULL)
        return;
    while(n!=NULL){
        cout<<n->data<<" ";
        n=n->next;
    }
    cout<<endl;
}

Node* Node::findTail(Node** head_ref){
    Node* n= *head_ref;
    while(n->next!=NULL)
        n=n->next;
    return(n);
}

我如何编译和运行我的代码。在这种情况下,有什么更好的方法可以在 VS Code 上编译和运行或调试?

g++ main.cpp Node.cpp

标签: c++classdebugginglinked-listcompilation

解决方案


推荐阅读