When a std::string
is ""
or a vector has no elements, is begin()
equal to end()
?
If so, what the value of begin()
/end()
?
When a std::string
is ""
or a vector has no elements, is begin()
equal to end()
?
If so, what the value of begin()
/end()
?
When a std::string is "" or a vector has no elements, is begin() equal to end()?
Yes, for any empty standard library container, including std::string
and std::vector
, begin()
will return the same iterator as end()
.
If so, what the value of begin()/end()?
It will be an iterator which is unique to that container, but should not be dereferenced. Doing so would cause undefined behavior.
Yes. Any STL container type with no elements will have begin() == end()
, as the range of elements is the half-open range [begin()
, end()
).
Hope this helps!