This repository contains starter code for Stanford CS106L, a course on Standard C++ programming.
Before getting started, a few prerequisites:
- You will need Python 3.8 or higher on your computer. You can check by running
python3 --version
(python --version
on Windows) in a terminal. - You will need an IDE you can code in. We encourage you to use VSCode for this class (see guide below), but you may use any IDE that you can comfortably write and compile C++ code in.
- You will need Git. If you are using VSCode, you should already have this. You can check by running
git --version
in a terminal.
Next, download the starter code. Open up a terminal (if you are using VSCode, hit Ctrl+` or go to Terminal > New Terminal at the top) and run the following command:
git clone https://github.com/cs106l/cs106l-assignments.git
which will download the starter code into a folder cs106l-assignments
. If you are using VSCode, you can then open up a VSCode workspace dedicated to CS106L:
cd cs106l-assignments && code .
and you are ready to go!
As we update existing assignments and release new ones, we will push updates to this repository. To fetch a new assignment, open up a terminal to your cs106l-assignments
directory and run
git pull origin main
You should now have the latest starter code!
We recommend using VSCode to write C++ code for this class. See instructions below to setup VSCode/GCC for your machine.
Go to this link and download Visual Studio Code for Mac. Follow the instructions on this webpage under the section Installation.
Inside VSCode, head to the extensions tab and search for C/C++. Click on the C/C++ extension, and then click Install.
🥳 At this point you should successfully have VSCode on your Mac 👏
-
Check if you have Homebrew by running
If you get something like
brew --version
then skip step 2 and go to step 3. If you get anything else that looks sus then proceed to step 2!brew --version Homebrew 4.2.21
-
Run this command:
which is going to download Homebrew🍺 which is a package manager. Woot woot.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Run the following command:
which is going to install the compiler (GCC).
brew install gcc
-
Make note of which GCC version Homebrew installs. In most cases, this will be
g++-14
. By default, theg++
command on Mac is an alias to the built-inclang
compiler. We can fix this by runningto makeecho 'alias g++="g++-14"' >> ~/.zshrc
g++
point to the version of GCC we just installed. Changeg++-14
in the above command to whichever version of GCC you installed. -
Restart your terminal and verify that everything worked by running the following command:
g++ --version
These instructions are for Debian-based distributions, like Ubuntu. Tested on Ubuntu 20.04 LTS.
Go to this link and download Visual Studio Code for Linux. Follow the instructions on this webpage under the section Installation.
Inside VSCode, head to the extensions tab and search for C/C++. Click on the C/C++ extension, and then click Install.
🥳 At this point you should successfully have VSCode on your Linux machine 👏
- In a terminal, update the Ubuntu package lists by running
sudo apt-get update
- Next install the G++ compiler:
sudo apt-get install g++-10
- By default, the system version of G++ will be used. To change it to the version you just installed, you can configure Linux to use G++ version 10 or a higher version installed like so:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
- Restart your terminal and verify that GCC was installed correctly. You must have a GCC version of 10 or higher:
g++ --version
Go to this link and download Visual Studio Code for Windows. Follow the instructions on this webpage under the section Installation.
Inside VSCode, head to the extensions tab and search for C/C++. Click on the C/C++ extension, and then click Install.
🥳 At this point you should successfully have VSCode on your PC 👏
-
Follow the instructions at this link
- You should be doing the instructions under Installing the MinGW-w64 toolchain.
-
After fully following the instructions under Installing the MinGW-w64 toolchain you should now be able to verify everything worked by running the following command:
g++ --version