C++ 23 · Language basics

Loop over a container

Use auto and a range-based for loop. const auto& avoids copying each element.

for (const auto& item : items) {
    std::cout << item << '\n';
}

Official C++ 23 documentation

More language basics commands

All language basics commands · C++ 23 cheatsheet

Was this page helpful?