C++ Tutorial: STL Algorithms
sort, find, transform, accumulate, count_if, for_each, and other powerful algorithms from <algorithm> and <numeric>.
Algorithms that work on anything
The STL algorithms in `<algorithm>` and `<numeric>` work on any range — vectors, arrays, sets, even your own containers. They're the building blocks of every data processing pipeline.
Combined with lambdas, they're remarkably expressive: `sort(v.begin(), v.end(), [](auto& a, auto& b){ return a.score > b.score; })` — sort by score descending in one line.
What you'll learn in this C++ stl algorithms tutorial
This interactive C++ tutorial has 6 hands-on exercises. Estimated time: 18 minutes.
- sort and reverse — `sort` needs `<algorithm>`. Pass begin/end iterators and an optional comparator.
- find, find_if, count_if — Searching algorithms:
- transform — apply a function to every element — `transform` applies a function to each element and stores results:
- accumulate and reduce — `accumulate` from `<numeric>` folds a range to a single value:
- any_of, all_of, none_of — Boolean checks on ranges:
- Build a data pipeline — No starter code.
C++ STL Algorithms concepts covered
- Algorithms that work on anything