can you tell me how should i install the c++ compiler on VS code?
1. Download and Install Visual Studio Code
- Go to code.visualstudio.com and download Visual Studio Code
- Install and at the 'additional tasks' section make sure "Open With Code" and "Add to Path" are selected
2. Download and Install a compiler
You can either use MSVC that comes with Visual Studio (not VSCode) or use GCC as part of a mingw distrubion, I recommend using nuwen's distro as it is small and fairly recent.
- Go to the MinGW Distro page and download the self-extracting archive [1]
- Select a target directory to install it to, (e.g. C:\)
- Add the bin directory to your environment path (the bin directory is your target directory + MinGW\bin, so in this case it would be C:\MinGW\bin)
- You should be able to open a command prompt and verify your compiler is found, e.g. by entering gcc --version
3. Setup Visual Studio Code
- Open VSCode and head over to the extension menu (CTRL + SHIFT + X) on the left hand side, search for the C/C++ extension by Microsoft and install it and restart Visual Studio Code afterwards.
4. Getting started
- Create a folder for your project, right-click and "Open with Code". Whenever you opened a workspace the status bar at the bottom will be blue. Otherwise it will be purple.
- Create a file and write your code.
- On the left hand side, select the "Run" option (CTRL + SHIFT + D) and click "Run and Debug", select "C++ (GDB/LLDB)" and g++ as the compiler.
- This will create the default launch configuration. Pressing "F5" will build and start your currently focused file.
- At this point IntelliSense should be working and you should be able to set breakpoints and step through your code.