Hi friends! I wanted to share with y’all how I’ve set up VSCode to do the C++ exercises. My motivation for doing this is because I’m trying to replicate my development environment at my job (code lives in a Linux VM, using VSCode for remote development, no CLion licenses yet). I learned a lot from setting this up (and maybe spent too much time), but I wanted to share what I’ve learned!
The following steps assume you’ve installed C++ locally and can test locally.
VSCode Extensions you’ll need (at minimum):
The configs I’m sharing also use a folder setup like shown below, where my workspace/root folder cpp has each exercise within it.
A few things to note:
.ideafolder is for CLion (which is now free for non-commercial use!).clang-formatand.clang-tidy, something I’ve made that I’m still messing around with to use with.gitignore, since this is also a personal git repocpp.code-workspaceis where I keep my VSCode settings that are specific for this Exercism folder (I have similar files for other tracks)
Most importantly, I have a root-level CMakeLists.txt that I’ve written myself. It looks like this:
cmake_minimum_required(VERSION 3.5.1)
project(exercism-cpp CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(allergies)
add_subdirectory(armstrong-numbers)
add_subdirectory(atbash-cipher)
add_subdirectory(bob)
add_subdirectory(darts)
add_subdirectory(difference-of-squares)
# add the same two lines for each exercise you download
This allows me to see all test files and cases in the Testing panel (the flask icon on the left) via the TestMate C++ extension (which I found to be the easiest to configure).
Now that we have a convenient view, we need to set up the build and debug tasks.
You’ll then need to add this task to your tasks.json (in .vscode folder) if you don’t already have that file:
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"${fileDirname}/test/tests-main.cpp",
"-o",
"${fileDirname}/build/${fileDirnameBasename}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"dependsOn": [
"builddir"
],
"group": {
"kind": "build",
"isDefault": true
}
}
And this configuration in your launch.json (also in .vscode folder):
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/build/${fileDirnameBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "MKH C/C++: g++ build active file"
}
Finally, you’ll need to adjust this setting from the default in settings.json (also in .vscode folder) or your .code-workspace file if you’re using that:
"testMate.cpp.test.executables": "{build,Build,BUILD,out,Out,OUT}/**",
Now your testing panel will look something like this:
You can then add breakpoints to your code, and run/debug each test case (or entire test set) from this panel, or in the *-test.cpp file itself:
Et Voilà! Now you can run and debug all of the test cases before you submit. Try it out!


