C++ Quick Reference Guide

A concise guide for reviewing C++ basics.

Learning C++

learncpp.com is a highly recommended resource for learning C++.

Prerequisites

A C++ compiler is required. On macOS, clang++ and g++ are available via Xcode Developer Tools. Verify installation by running:


                $ clang++ --help
$ g++ --help
            

Basic clang++ Commands

Compiling a C++ File

Consider a simple program, hello-world.cpp:


                #include <iostream>
int main() {
    std::cout << "Hello, world!\n";
    return 0;
}
            

Compile it using:


                $ clang++ hello-world.cpp
            

This generates an executable named a.out.

Running the Program

Execute the compiled program:


                $ ./a.out
Hello, world!
            

Specifying Output File Name

To customize the executable’s name, use the -o flag:


                $ clang++ hello-world.cpp -o hello-world
$ ./hello-world
Hello, world!