What You’ll Need
- Visual Studio Code
- C++ compiler (
clangfor Mac) - VS Code C++ extensions
1. Install Xcode Command Line Tools (includes clang)
Open Terminal and run:
xcode-select --install
Follow the prompt to install the tools.
2. Install Visual Studio Code
Download and install from:
https://code.visualstudio.com
3. Install C++ Extension in VS Code
- Open VS Code
- Go to the Extensions tab (left sidebar or
Cmd+Shift+X) - Search for and install:
- C/C++ by Microsoft
4. Create and Run a C++ Program
- Create a new folder for your project (e.g.,
cpp-labs) - Open the folder in VS Code:
File→Open Folder - Create a new file:
hello.cpp
Paste the following:
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
- Open the Terminal in VS Code:
Terminal→New Terminal - Compile the code:
clang++ hello.cpp -o hello
- Run the program:
./hello
You should see:
Hello, world!‘Hello, world!
