Iterators

closed account (EwCjE3v7)
Will this point at the null character or ine past that

1
2
  string sv = "Hello";
  auto svend = sv.end();
A string doesn't have a null terminator. It knows where the string content begins and ends.

The null terminator is supplied for C compatibility in member c_str().

svend points to one past the end of the string.
In C++11 the std::string is null terminated but you are not allowed to dereference the end iterator.
@Peter87: to clarify, I think you mean that there has to be a null terminator in memory after the end of the string? This has always been the guarantee for .c_str() but not for .data(), could you link to somewhere explaining this difference or quote the standard?
closed account (EwCjE3v7)
Thank you so if I move svend back by one will it point to 'o'?
Yes
@LB Yes that is what I mean. In C++11 the specification is the same for both data() and c_str().

C++11 ยง21.4.7.1 basic_string accessors
const charT* c_str() const noexcept;
const charT* data() const noexcept;

Returns: A pointer p such that p + i == &operator[](i) for each i in [0,size()].
Complexity: constant time.
Requires: The program shall not alter any of the values stored in the character array.
closed account (EwCjE3v7)
Thank you guys, nooby here so yea. Thanks
Topic archived. No new replies allowed.