LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What is the STL in C++?

STL = Standard Template Library — a collection of generic containers, iterators, and algorithms.

Containers expose iterators, iterators drive algorithms, algorithms operate on the containers

* Iterators are the glue: containers expose them, and algorithms are written against them — so sort() works on any container without knowing its type. *

It's C++'s rough equivalent of C's standard library, but built on templates so it works for any element type.

Component Examples Purpose
Containers vector, map, list, set Store data (complex data types)
Iterators begin(), end() Walk through a container
Algorithms sort(), find(), count() Operate on data via iterators

Example:

#include <vector>
#include <algorithm>

vector<int> v = {3, 1, 4, 1, 5};
sort(v.begin(), v.end());   // v is now {1, 1, 3, 4, 5}

Why use the STL?

  • Type-safe (templates) and well-tested
  • A consistent interface across containers (iterators glue containers to algorithms)
  • Far less error-prone than hand-rolling data structures with raw arrays and pointers

Go deeper:

From Quiz: REVE1 / C++ Programming | Updated: Jul 14, 2026