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

后端 未结 1 712
时光取名叫无心
时光取名叫无心 2020-12-20 16:24

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 o

1条回答
  •  甜味超标
    2020-12-20 16:42

    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.

    0 讨论(0)
提交回复
热议问题