This may seem frivolous to some of you, but which of the following 2 methods of iteration over a STL container is better? Why?
The following method of iteration over a standard library container is best.
Use c++11 (and beyond)'s range-based for-loop with the auto specifier:
// Method 2
for (auto& e: elemVec)
{
// Do something with e...
}
This is similar to your Method 0 but requires less typing, less maintenence and works with any container compatible with std::begin() and std::end(), including plain-old arrays.