Zest.

C++: Loop over a vector

A short, tested C++ example for loop over a vector. Copy it and adjust the names and paths for your project.

C++
std::vector<int> v = {1, 2, 3};
for (int x : v) std::cout << x << "\n";
for (auto& x : v) x *= 2;          // modify in place
for (size_t i = 0; i < v.size(); ++i) { /* index */ }

Find it in Zest

Search for “cpp loop over a vector” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More C++ examples

All C++ examples