c++ - 调试和编译类依赖于 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
解决方案
推荐阅读
- sharepoint - Graph API 403 Forbidden - 令牌中需要存在 scp 或角色声明
- apache-flink - Flink - 具有高并行度的网络缓冲区数量不足
- c# - 文本的重叠部分变得透明 GDI+
- rabbitmq - rabbitMq中的事件交换规则
- angular - Angular Reactive Forms:如何显示错误+红色边框?
- pandas - 如何删除列表中的那些列元素的行?
- python - 在 Python 中重新格式化 DataFrame
- javascript - Twitter引导模式在底部滚动条时侦听
- arrays - 将循环中的答案添加到列表中
- php - 带有连接的 PostgreSQL 查询仅通过 AJAX 给出“内部服务器错误”(不在 pgAdmin 上)