coderef

C++ Quick Reference

Modern C++: I/O, strings, vectors, maps, algorithms, classes, smart pointers, lambdas and compiling.

6 sections · 34 snippets · updated Oct 14, 2026

Click any snippet to copy it.

Basics

Program structure and I/O.

  • Hello world
  • Variables
  • Read input
  • Read a whole line
  • Format (C++20)

Strings

std::string.

  • Create / length
  • Concatenate
  • Substring / find
  • Convert numbers
  • Compare

Containers

Vectors, maps and sets.

  • Vector
  • Access / size
  • Loop
  • Map
  • Hash map / find
  • Set
  • Pair / tuple

Algorithms

<algorithm> and ranges.

  • Sort
  • Sort descending / by key
  • Find
  • Count / sum
  • Min / max
  • Reverse

Classes & memory

Objects and ownership.

  • Class
  • Inheritance
  • Virtual method
  • Unique pointer
  • Shared pointer
  • Lambda
  • Struct

Errors & building

Exceptions and compiling.

  • Try / catch
  • Throw
  • Optional
  • Compile

← All quick references