The C++11 introduced ranged-based for loop that is internally implemented using (const) iterators so this:
std::vector vec;
for(std::stri
Yes, that's a valid solution. The underlying data is guaranteed to be contiguous (std::vector
is supposed to be a dynamic array, more or less).
n4140 §23.3.6.1 [vector.overview]/1
The elements of a
vector
are stored contiguously, meaning that ifv
is avector
whereT
is some type other thanbool
, then it obeys the identity&v[n] == &v[0] + n
for all0 <= n < v.size()