Will std::string always be null-terminated in C++11?
Solution 1:
Yes. Per the C++0x FDIS 21.4.7.1/1, std::basic_string::c_str()
must return
a pointer
p
such thatp + i == &operator[](i)
for eachi
in[0,size()]
.
This means that given a string s
, the pointer returned by s.c_str()
must be the same as the address of the initial character in the string (&s[0]
).