DevAcademia lesson/C++ Modern Essentials
C++ STL Containers
Topic progressTopic 102 of 109 - 94% complete
~14 min lesson10 learning blocks2 code examples1 checks/interactions
Lesson outline
The Standard Template Library (STL)
The STL provides ready-made, type-safe containers so you rarely need raw C-style arrays or manual memory. The most common are std::vector (a dynamic array), std::map (sorted key/value pairs), and std::set (unique sorted values).
std::vector - a Resizable Array
| Operation | Meaning |
|---|---|
| v.push_back(x) | Append x to the end |
| v[i] / v.at(i) | Access by index (at() is bounds-checked) |
| v.size() | Number of elements |
| v.front() / v.back() | First / last element |
| for (auto x : v) | Range-based iteration |
std::map - Sorted Key/Value Pairs
A std::map stores entries sorted by key and gives O(log n) lookup. C++17 structured bindings make iteration clean.
Was this topic clear?