Writing C++ with Visual Studio Code on Windows 10

It’s a Friday evening and I’ve decided as always, to write some code. Since I haven’t worked with C++ for some time, I decided to try it out but there was a problem, I’m on Windows 10.

It took me few minutes to figure it out but I eventually managed to make the compiler properly work with my Visual Studio Code. Not to bore you too much, these are the steps you need to do to make your C++ compile properly.

  1. Download and install MinGW from Download MinGW. Make sure to select mingw32-gcc-g++ compiler (The GNU C++ compiler), mingw-developer-toolkit and mingw32-base
  2. Add MinGW to your PATH variable (C:\MinGW\bin)
  3. Install C++ plugin for Visual Studio Code.
  4. C/C++ for VS Code
  5. Like the above link stated, you must generate two files, c_cpp_properties.json and tasks.json.
  6. Your tasks.json should look something like this:
    {
      "version":"0.1.0",
      "command":"g++",
      "isShellCommand":true,
      "showOutput":"always",
      "args":[
     "-g",
     "main.cpp"
      ]
    }
    

    You can optionally compile your code from integrated VSC terminal (or any other) by typing g++ -g main.cpp

  7. In your c_cpp_properties.json, make sure to add a path to your your includes.
{
  "name":"Win32",
  "includePath":[
    "${workspaceRoot}"
  ],
  "defines":[
    "_DEBUG",
    "UNICODE"
  ],
  "intelliSenseMode":"msvc-x64",
  "browse":{
    "path":[
      "C:/MinGW/lib/gcc/mingw32/5.3.0/include/"
    ],
    "limitSymbolsToIncludedHeaders":true,
    "databaseFilename":""
  }
}
  1. You are done. In case you are having issues compiling your code, make sure to restart your terminal and your VSC.