vector for loop in c++ code example
Example 1: c++ iterate over vector
for(auto const& value: a) {
}
Example 2: iterate over vector in c++
for (auto & element : vector) {
element.doSomething ();
}
Example 3: for loop vector
for (auto i = v.begin(); i != v.end(); i++)
{
std::cout << *i << endl;
}
Example 4: c++ looping through a vector
for(std::vector<T>::size_type i = 0; i != v.size(); i++) {
v[i].doSomething();
}
Example 5: c++ looping through a vector
vector<int> vi;
...
for(int i : vi)
cout << "i = " << i << endl;