Skip to content
techsnow

Object-Oriented C++

STL Containers

The Standard Template Library gives you ready-made data structures.

ContainerUse for
vectorDynamic list
mapSorted key-value pairs
unordered_mapFast key-value lookup
setSorted unique values
stack / queueLIFO / FIFO
pairTwo values together
#include <map>

map<string, int> stock;
stock["apple"] = 10;
stock["mango"] = 4;
for (auto [fruit, qty] : stock) {
    cout << fruit << " " << qty << endl;
}

Output

apple 10
mango 4