C++workingcpp20

Vectors and <algorithm>

The container you reach for first, and the verbs that act on it.

std::vector plus the <algorithm> header replace most hand-written loops — sort, transform, accumulate, all in one line.

Sort, transform, accumulate

C++intro
0ms
1 2 3 5 8 9sum of squares: 184
Reference · output compiled offline, not runnable in-browser

The sorted line shows std::sort reordering the vector in place ascending, and 184 is std::accumulate summing the squares (1+4+9+25+64+81) produced by std::transform — three algorithms compose over the same iterator range with no hand-written loop.