CPP set up in vscode

Any one using vscode for c++ for cp if so,please help me out to set up ?
I find difficult in setting c++ environment in visual studio code editor??

Get the following extensions



I’m assuming you already have MinGW installed. If not download that from https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/
and put minGW in the include path.

Download the GCC Compiler from here:

GCC Compiler

Download the Code Runner Extension for VS Code here:

Code Runner Extension

You can also install the C/C++ Extension which is really useful for debugging

C/C++ Extension

After installing these, Go to File->Preferences->Settings and then search for “Code Runner” and tick the checkbox showing “Run in Terminal” to get input and view the output in terminal.

After that, in the same page there will be an option for editing the “Executor Map”
In the JSON file, “code-runner.executorMap” you can add custom command for your compilation.
This is what I use: “cpp”: “cls && cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt”,
The cls in the command is to clear the previous output in the terminal. If you don’t want the previous output to be cleared, you can delete cls && in the command.
Feel free to change the C++ version to 11/14/17 in the same command.

Extra tip: I am using user-snippets option in C++ to instantly get a C++ snippet.
For this, you can go to File->Preferences->User snippets
Then click on C++ to edit the C++ json file. I have given my snippet in the below link. Feel free to change the prefix to what you need. After this, all you need to do is type your prefix in a C++ file and the code appears instantly.

User Snippet C++

1 Like

Guys, Ive setup the development environment in VS Code without this extension. That consists of taking input from file, presenting the output to a file, debugging with UI and the code snippets with your own custom template. Drop me a mail at bharatchauhan51@gmail.com if anyone wants any assistance with that. Thanks

This video will be helpful for you. It is a complete tutorial to set up VS code for C++.
Link: https://www.youtube.com/watch?v=WFqLqzsOIt4

1 Like