The Standard Template Library (STL) in Depth
Common containers
#include <map>n#include <set>nnstd::map<std::string, int> scores;nscores["Yash"] = 95;nscores["Ana"] = 88;nnstd::set<std::string> uniqueCourses;nuniqueCourses.insert("C++");nuniqueCourses.insert("C++"); // ignored -- sets don't allow duplicatesnstd::cout << uniqueCourses.size(); // 1
std::map keeps its keys sorted automatically (an unordered_map variant trades that ordering for typically faster average lookups). Both give you the same key-value lookup idea you’ve already seen in Python’s dictionaries and Java’s HashMap.
Algorithms
#include <algorithm>n#include <numeric>nnstd::vector<int> scores = {90, 85, 78, 92};nstd::sort(scores.begin(), scores.end());nauto it = std::find(scores.begin(), scores.end(), 85);nint total = std::accumulate(scores.begin(), scores.end(), 0);
The STL splits cleanly into containers (vector, map, set) and algorithms (sort, find, accumulate) that work on any of them through iterators — a shared, uniform interface for “a position within a sequence.” Learn this container/algorithm/iterator split and most of the standard library becomes predictable rather than something to memorize piece by piece.
Iterators, briefly
scores.begin() and scores.end() return iterators marking the start and one-past-the-end of the vector — this “one-past-the-end” convention is the same idea behind Python’s range() stopping one before the number you give it, and it shows up throughout the STL consistently.
Choosing the right container
Reach for vector by default. Reach for map when you need fast lookups by a key. Reach for set when duplicates should be structurally impossible. This mirrors exactly the same decision you’d make choosing between a Python list, dict, and set, or a Java ArrayList, HashMap, and HashSet.