[visual-studio-code] How do I set up Visual Studio Code to compile C++ code?

With an updated VS Code you can do it in the following manner:

  1. Hit (Ctrl+P) and type:

    ext install cpptools
    
  2. Open a folder (Ctrl+K & Ctrl+O) and create a new file inside the folder with the extension .cpp (ex: hello.cpp):

  3. Type in your code and hit save.

  4. Hit (Ctrl+Shift+P and type, Configure task runner and then select other at the bottom of the list.

  5. Create a batch file in the same folder with the name build.bat and include the following code to the body of the file:

    @echo off
    call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64     
    set compilerflags=/Od /Zi /EHsc
    set linkerflags=/OUT:hello.exe
    cl.exe %compilerflags% hello.cpp /link %linkerflags%
    
  6. Edit the task.json file as follows and save it:

    {
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "build.bat",
    "isShellCommand": true,
    //"args": ["Hello World"],
    "showOutput": "always"
    }
    
  7. Hit (Ctrl+Shift+B to run Build task. This will create the .obj and .exe files for the project.

  8. For debugging the project, Hit F5 and select C++(Windows).

  9. In launch.json file, edit the following line and save the file:

    "program": "${workspaceRoot}/hello.exe",
    
  10. Hit F5.