cpp-cheatsheet: A Comprehensive Modern C++ Reference Guide

cpp-cheatsheet: A Comprehensive Modern C++ Reference Guide

Summary

The cpp-cheatsheet repository by mortennobel offers a concise and comprehensive reference for modern C++, covering C++11 and C++14 features. It serves as an invaluable resource for developers looking for quick syntax reminders and standard library usage. This cheatsheet is ideal for both learning and daily development tasks.

Repository Info

Updated on March 1, 2026
View on GitHub

Tags

Click on any tag to explore related repositories

Introduction

The cpp-cheatsheet repository, maintained by mortennobel, provides a concise and comprehensive reference for modern C++. This cheatsheet is an invaluable resource for anyone working with C++, specifically focusing on features introduced in C++11 and C++14. It is based on Phillip M. Duxbury's C++ Cheatsheet and further edited by Morten Nobel-Jørgensen, with C++11 additions inspired by ISOCPP.org. The primary goal is to offer a clear, quick overview of essential C++ concepts and standard library components.

Installation

To make use of the cpp-cheatsheet, there is no traditional "installation" required as it is a documentation-based repository. You can access the full content directly on GitHub or clone the repository to have a local copy for offline reference.

To clone the repository, use the following command:

git clone https://github.com/mortennobel/cpp-cheatsheet.git

Once cloned, you can open the README.md file in your preferred markdown viewer or directly browse the content in your terminal.

Examples

The cheatsheet covers a wide range of C++ topics, from basic syntax to advanced features and standard library usage. Here are a few examples of the structured information you'll find:

Preprocessor

                            // Comment to end of line
                            /* Multi-line comment */
#include  <stdio.h>         // Insert standard header file
#include "myfile.h"         // Insert file in current directory
#define X some text         // Replace X with some text
#define F(a,b) a+b          // Replace F(1,2) with 1+2
#define X \
 some text                  // Multiline definition
#undef X                    // Remove definition
#if defined(X)              // Conditional compilation (#ifdef X)
#else                       // Optional (#ifndef X or #if !defined(X))
#endif                      // Required after #if, #ifdef

Literals

255, 0377, 0xff             // Integers (decimal, octal, hex)
2147483647L, 0x7fffffffl    // Long (32-bit) integers
123.0, 1.23e2               // double (real) numbers
'a', '\141', '\x61'         // Character (literal, octal, hex)
'\n', '\\', '\'', '\"'      // Newline, backslash, single quote, double quote
"string\n"                  // Array of characters ending with newline and \0
"hello" "world"             // Concatenated strings
true, false                 // bool constants 1 and 0
nullptr                     // Pointer type with the address of 0

Memory Management with shared_ptr

#include <memory>           // Include memory (std namespace)
shared_ptr<int> x;          // Empty shared_ptr to a integer on heap. Uses reference counting for cleaning up objects.
x = make_shared<int>(12);   // Allocate value 12 on heap
shared_ptr<int> y = x;      // Copy shared_ptr, implicit changes reference count to 2.
cout << *y;                 // Dereference y to print '12'
if (y.get() == x.get()) {   // Raw pointers (here x == y)
    cout << "Same";  
}  
y.reset();                  // Eliminate one owner of object
if (y.get() != x.get()) { 
    cout << "Different";  
}  
if (y == nullptr) {         // Can compare against nullptr (here returns true)
    cout << "Empty";  
}  
y = make_shared<int>(15);   // Assign new value
cout << *y;                 // Dereference x to print '15'
cout << *x;                 // Dereference x to print '12'

Why Use This

The cpp-cheatsheet is an excellent resource for several reasons:

  • Comprehensive Coverage: It provides a broad overview of C++ syntax, standard library components, and modern features up to C++14.
  • Quick Reference: Its concise format makes it perfect for quickly looking up syntax or function signatures during development or study.
  • Educational Tool: Ideal for students learning C++ or experienced developers brushing up on specific topics.
  • Modern C++ Focus: Explicitly highlights C++11 and C++14 additions, ensuring relevance for contemporary projects.
  • Community Driven: The repository encourages comments and feedback, fostering continuous improvement.

Links