My code is correct but it doesnt run on my vscode

Viewed 268
#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);
}

error message:

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

This is error is shows after running code. After I run any program an .exe file is created but here the .exe file gets deleted by my antivirus because it says it is a trojan...

If I run code in an online compiler it works perfectly

1 Answers

if all you want to do is compile and run you can just do g++ Node.cpp -o Node ; .\Node

if you want to make sure program doesn't run in case of compilation error you can do g++ Node.cpp -o Node && .\Node

if these don't work try running these commands in run in administration mode

Also your command is not clear please repost your full command again or post a screenshot of the command line

Related