Configure VSCode for competitive programming

Long Nguyen
VTeam
Published in
2 min readAug 29, 2017

What is competitive programming?

Sites like CodeForces, TopCoder, HackerRank, CodeChef,… ACM-ICPC, Olympiad in Informatics (for high school students), Google Code Jam, Facebook Hacker Cup,…
Anything involves solving short problems in 2–5 hours by code using algorithms and data structures.

Requirements

  • High coding speed.
  • One-click compile and run for one source file.
  • Automatic linting
  • C++ (though Java and Python are viable, C++ is still preferable for superior performance).
  • Debugging

Why VSCode?

Lightweight, customizable, big userbase, open-source and has an awesome community.

Limitations

I still haven’t been able to figure out how to debug, even after reading VSCode’s official guide. So I actually have to resort to Xcode for (seldom) C++ debugging.

Instructions

Beware! The instructions below have only been tested on MacOS. I need some volunteers to help me test them on the other OSes.

  1. Setup a C++ compiler of your choice (GCC or Clang). After this step, you should be able to run the code by g++ a.cpp -o a.out && ./a.out or clang++ a.cpp -o a.out && ./a.out
  2. Setup these extensions:
  • C/C++ obviously
  • C/C++ Clang Command Adapter for linting, you can config Clang flags to -Weverything and disable warnings you don’t need.
  • Code Runner for one-click compile and run, you should set Code Runner to run in VSCode’s integrated Terminal, otherwise it would be impossible to use standard input.
  1. Set your hotkey for Code Runner, create your snippets and templates, and you are ready to go.

By the way, here is my personal settings:

"code-runner.runInTerminal": true,
"code-runner.executorMap": {
"cpp": "clang++ -Wl,-stack_size -Wl,0x10000000 -g -Wall -Wextra -pedantic -std=gnu++14 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fstack-protector $fileName -o Executable && ./Executable"
},
"code-runner.saveFileBeforeRun": true,
"code-runner.preserveFocus": false,
"code-runner.ignoreSelection": true,
"clang.cxxflags": ["-Weverything", "-pedantic", "-std=gnu++14", "-O2", "-Wno-c++98-compat", "-Wno-c++98-compat-pedantic", "-Wno-missing-variable-declarations", "-Wno-missing-prototypes"]

Useful stuff

UPDATE: There seems to be a cool extension dedicated for competitive programming which is IORun. You guys should check it out too!

--

--