Configure VSCode for competitive programming
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.
- 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).
Lightweight, customizable, familiar to some people (including me), open-source and has an awesome community.
I still haven’t been able to figure out how to debug, even after reading VSCode’s official guide. So I actually have to use Xcode for (seldom) C++ debugging.
Beware! The instructions below have only been tested on MacOS. I need some volunteers to help me test them on the other OSes.
- Setup a C++ compiler of your choice (GCC or Clang). After this step, you should be able to run this command:
g++ a.cpp -o a.out && ./a.outor
clang++ a.cpp -o a.out && ./a.out
- Setup these extensions:
- C/C++ of course…
- 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 make input.
- 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:
"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"
"clang.cxxflags": ["-Weverything", "-pedantic", "-std=gnu++14", "-O2", "-Wno-c++98-compat", "-Wno-c++98-compat-pedantic", "-Wno-missing-variable-declarations", "-Wno-missing-prototypes"]