itereate over a vector c++ code example
Example 1: iterate over vector in c++
for (auto & element : vector) {
element.doSomething ();
}
Example 2: iterate on vector c++
// vector::begin/end
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);
std::cout << "myvector contains:";
for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}