Behavior when dereferencing the .end() of a vector of strings

You said:

I’m wondering if it’s “safe” to set a string equal to whatever is returned by dereferencing the off-the-end iterator of a vector of strings

No, it is not safe. From http://en.cppreference.com/w/cpp/container/vector/end

Returns an iterator to the element following the last element of the container.

This element acts as a placeholder; attempting to access it results in undefined behavior.

Leave a Comment