C++ Tutorial: STL Containers
vector, map, set, unordered_map, list, deque, stack, queue — the C++ Standard Library containers.
The Standard Library of data structures
The STL provides production-quality data structures with guaranteed complexity. You never need to implement a hash map from scratch — `unordered_map` is already there, highly optimised.
Choosing the right container is the first performance decision in every C++ program.
What you'll learn in this C++ stl containers tutorial
This interactive C++ tutorial has 6 hands-on exercises. Estimated time: 20 minutes.
- map — sorted key-value pairs — `map<K, V>` stores key-value pairs sorted by key. O(log n) access.
- unordered_map — O(1) hash map — `unordered_map<K, V>` uses hashing — O(1) average access, faster than `map` for large datasets, but no ordering.
- set and unordered_set — unique items — `set<T>` stores unique sorted items. `unordered_set<T>` stores unique items with O(1) contains.
- stack, queue, and priority_queue — Adaptor containers wrap other containers:
- pair and tuple — `pair<T1, T2>` holds two values. `tuple<T1,T2,...>` holds any number.
- Build a frequency analyser — No starter code.
C++ STL Containers concepts covered
- The Standard Library of data structures