Longest string in a vector — two implementations
The first version of the algorithm uses a traditional C++03-era for loop with iterators. The only modern element is the auto used to deduce an std::vector&lt;std::string&gt;::iterator. The second loop uses a C++11 range-based for loop whose syntax is close to the one used in Java. The range-based for loop is now preferred for several reasons:


Its terse syntax (when iterators are fully spelled out, a traditional for loop is ugly).
Its genericity: a range-based for loop also works with C arrays and std::valarray.
end is automatically cached instead of being evaluated at each iteration.




That's it for the for loops: the range-based for loop is preferred. However, there are some things that could be improved in your second version:


You should pass lines as a const reference. When you don't need to modify an instance, a const reference is good since it avoids a useless copy.
In your range-based for loop, you should write const auto&amp; since you don't modify line either. It currently performs many useless copies of full std::strings just to get their size. Actually, the best thing to write in range-based for loops is generally auto&amp;&amp;, but the explanation may be a little complicated since it involves lvalues, rvalues, const-correctness and type deduction.