Rohit Bhati
Rohit Bhati

Reputation: 11

C++ not running in vs code

I am trying to run my C++ code in vs code. I have installed global extension for C/C++ by Microsoft and also code runner extension. When I run my code it shows this in the terminal.

user@LAPTOP-7LH95TTK MINGW64 ~/Desktop
$ cd "c:\Users\user\Desktop\" && g++ demo.cpp -o demo && "c:\Users\user\Desktop\"demo
bash: cd: c:\Users\user\Desktop" && g++ demo.cpp -o demo && c:UsersuserDesktop"demo: No such file or directory

What should I do ? I think the default command that shows up in the terminal when I run my code is incorrect and I don't know how to change it.

Below is the code from demo.cpp file

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"Hello everyone"<<endl;
    return 0;
}

Upvotes: 0

Views: 31953

Answers (2)

poshiplatta bagati
poshiplatta bagati

Reputation: 1

I think you should download Mingw gcc compiler and install it in your system properly step by step.

  1. click on Advanced setting by right click on My Pc
  2. click on Environment Varaiable
  3. move to System Variable there
  4. take cursor on PATH click
  5. click on Edit
  6. click New
  7. copy the C:\Mingw\bin or where you have installed
  8. Move the new Path to Top
  9. Click ok

Your problem Solved

Upvotes: 0

AdityaG15
AdityaG15

Reputation: 290

You can read through https://code.visualstudio.com/docs/cpp/config-mingw (if using MinGw).

If you have MSVC (MS C++ Compiler) installed, instead of 'g++' command you would be using the 'cl' command to compile (the guide for that is at https://code.visualstudio.com/docs/cpp/config-msvc).

Just a brief of the article:

You should have a tasks.json file inside .vscode.

It is the file that is used for instructions to build your code

And, there can be a launch.json also, that is used by VS Code for instructions to debug it. (Not Required)

What i generally do, is click this "Create a launch.json" in the Debug tab, which will ask you to chose the toolchain (compiler,...), and create tasks.json, and launch.json for you.

You can then just use "Shift+Ctrl+B" (default), to just build the code. The debugging option is just a plus, you will require sooner or later :D

Create a launch.json file

Upvotes: 1

Related Questions