The Standard Template Library’s workhorses: vector and string, associative containers (map, set, unordered_map), and the iterators and streams that tie them together.
std::vector is a growable array and your default container — contiguous, cache-friendly, and self-managing. std::string is a vector of characters with text operations. Both own their memory (Rule of Zero), so you never new or delete them.
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<int> v;
v.push_back(10);
v.push_back(20);
v.emplace_back(30); // construct in place
std::cout << v.size() << " " << v[1] << "\n"; // 3 20
std::string s = "C++";
s += "20";
std::cout << s << " " << s.substr(3) << "\n"; // C++20 20
return 0;
}std::map keeps sorted key→value pairs; std::unordered_map uses a hash table for average O(1) lookup and no ordering. std::set stores unique keys. Prefer the unordered variants when you don’t need order and want speed.
#include <iostream>
#include <map>
#include <unordered_map>
#include <string>
int main() {
std::unordered_map<std::string, int> ages;
ages["Ada"] = 36;
ages["Alan"] = 41;
if (auto it = ages.find("Ada"); it != ages.end())
std::cout << it->first << " -> " << it->second << "\n"; // Ada -> 36
std::map<std::string, int> sorted(ages.begin(), ages.end());
for (const auto& [name, age] : sorted) // structured bindings
std::cout << name << ' ' << age << "\n"; // Ada, then Alan (sorted)
return 0;
}Iterators are the glue of the STL: a pair (begin, end) describes a range that any algorithm can walk, regardless of container. Streams model input and output the same way. Understanding iterators is what makes the next lesson’s algorithms click.
#include <iostream>
#include <vector>
#include <iterator>
#include <numeric>
int main() {
std::vector<int> v{1, 2, 3, 4};
// an iterator is a generalized pointer into the range [begin, end)
for (auto it = v.begin(); it != v.end(); ++it)
std::cout << *it << ' ';
std::cout << "\n";
long total = std::accumulate(v.begin(), v.end(), 0L); // 10
std::cout << total << "\n";
return 0;
}