首页 > 解决方案 > 我的代码是正确的,但它不能在我的 vscode 上运行

问题描述

#include<iostream>
using namespace std;

struct node{  
    int data;
    struct node *next;
}*first;

void create(int a[],int n)
{
    int i;
    struct node *t, *last;
    first = new struct node;
    first->data = a[0];
    first->next = NULL;
    last=first;
 
    for (i=1;i<n;i++){
        t=new node;
        t->data=a[i];
        t->next=NULL;
        last->next=t;
        last=t;
    }
}

void display(struct node *p){
    while(p!=NULL){
        cout<<p->data<<" ";
        p=p->next;
    }
}

int main(){
    int A[] = {3,5,7,10,15};
    create(A,5);
    display(first);
}

错误信息:

Program 'Node.exe' failed to run: Access is deniedAt line:1 char:83
+ ... inked lists\" ; if ($?) { g++ Node.cpp -o Node } ; if ($?) { 
.\Node }
+                                                                  
~~~~~~.
At line:1 char:83
+ ... inked lists\" ; if ($?) { g++ Node.cpp -o Node } ; if ($?) { 
.\Node }
+                                                                  
~~~~~~
+ CategoryInfo          : ResourceUnavailable: (:) [], 
ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed

这是运行代码后显示的错误。在我运行任何程序后,.exe会创建一个文件,但在这里该.exe文件被我的防病毒软件删除,因为它说它是一个特洛伊木马......

如果我在在线编译器中运行代码,它会完美运行

标签: c++visual-studio-code

解决方案


如果您只想编译和运行,您可以这样做 g++ Node.cpp -o Node ; .\Node

如果你想确保程序在编译错误的情况下不运行,你可以这样做g++ Node.cpp -o Node && .\Node

如果这些不起作用,请尝试在管理模式下运行这些命令

另外您的命令不清楚请重新发布您的完整命令或发布命令行截图


推荐阅读