Setting Up a C/C++ Development Environment in Visual Studio Code
Visual Studio Code (VS Code) is a lightweight, cross-platform source code editor developed by Microsoft. It runs on Windows, macOS, and Linux, offering consistent functionality across operating systems. Built-in features such as syntax highlighting, intelligent code completion, bracket matching, and customizable keybindings enhance developer productivity.
While VS Code supports many languages out of the box, C/C++ support is added via extensinos. Combined with an external compiler like GCC, it becomes a capable environment for C/C++ development.
Installing VS Code
Download and install VS Code from the official website: https://code.visualstudio.com/
Installing a C/C++ Compiler
On Windows, MinGW-w64 provides a complete GCC toolchain. Download it from:
https://sourceforge.net/projects/mingw-w64/files/
Choose any recent version for Windows, then extract the archive. For example, extract to:
F:\ProgramSoftware\GCC\mingw64
Configuring Environment Variables
Add the compiler’s bin directory to your system’s PATH:
- Copy the path:
F:\ProgramSoftware\GCC\mingw64\bin - Open System Environment Variables
- Edit the Path variable under System variables
- Add a new entry with the copied path
- Save and restart any open terminals
Verifying the Setup
Create a test file named hello.cpp:
#include <iostream>
int main() {
std::cout << "Hello, C++!" << std::endl;
return 0;
}
Open a terminal in VS Code and run:
g++ hello.cpp -o hello
./hello
If the output displays Hello, C++!, the environment is correctly configured.
Best Practices
Avoid using integrated build buttons or tasks for simple projects during initial setup. Instead, compile and run manually via the terminal to ensure full control and visibility over the build process.