Skip to content

Instantly share code, notes, and snippets.

@johnsogg
Last active January 11, 2024 02:14
Show Gist options
  • Save johnsogg/76cf7f8eeb5b134480a59c14ec597198 to your computer and use it in GitHub Desktop.
Save johnsogg/76cf7f8eeb5b134480a59c14ec597198 to your computer and use it in GitHub Desktop.
C++ Crash Course

C++ Crash Course

If you're new to the command line please see the CLI crash course first. Similarly, there's a Git crash course also.

This crash course is aimed at my Data Structures students in CS 2270 at CU-Boulder. Others might find it useful, though this is hardly the only "how to c++" thing on the web. This is tailored for the particular workflow in our course.

Specific Advice for 2270 Students

The general workflow for 2270 homework assignments is:

  1. Use git to clone a repository. Our repositories have restricted access so you need to either set up your SSH key, or use a personal access token (PAT).
  2. Change directory into that repo's build directory.
  3. Run cmake .. one time to set up the build process for your computer (because it is different between Windows/Mac/Linux). Using CMake is popular but not universal.
  4. Edit your code in your favorite editor.
  5. Run make to build the app and test binaries.
  6. Run ./run_tests to see what works and what doesn't.
  7. Go back to step 4 and repeat until you win!
    • Hint: you can use the up arrow to scroll through previous commands.
    • Hint: Type make && ./run_tests to build and run tests in a single command.
  8. When you're ready to check in your code, use a series of git commands to manage your changes:
    1. git status to see what changes you've made. It gives a list of files that you could work with.
    2. git add to stage files one at a time or in a big batch
    3. git commit to store the changes on your local computer, along with a commit message
    4. git push to store your changes on the remote computer (which is GitHub in our case).

The above process is exactly the same if you're using an editor with built-in tooling. I personally use VS Code, and I can use either my editor or the CLI to do these things, since ultimately they are working on the same source of truth. The CLI is generally available everywhere though, so you should try to learn how to do it.

Here's an example session with output removed to demonstrate:

$ git clone [email protected]:cu-cspb-2270-Fall-2023/pa8-johnsogg.git
$ cd pa8-johnsogg 
pa8-johnsogg git:(master) $ cd build
build git:(master) $ cmake ..
build git:(master) $ make
build git:(master) $ ./run_tests 
build git:(master) $ git status
build git:(master) $ git add ../code/Huffman.cpp
build git:(master) $ git commit -m "Made it super perfect"
build git:(master) $ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment