What is the internal structure of std::wstring? Does it include the length? Is it null terminated? Both?
Does it include the length
Yes. It's required by the C++11 standard.
§ 21.4.4
size_type size() const noexcept;
1. Returns: A count of the number of char-like objects currently in the string.
2. Complexity: constant time.
Note however, that this is unaware of unicode.
Is it null terminated
Yes. It's also required by the C++11 standard that std::basic_string::c_str
returns a valid pointer for the range of [0,size()] in which my_string[my_string.size()]
will be valid, hence a null character.
§ 21.4.7.1
const charT* c_str() const noexcept;
const charT* data() const noexcept;
1. Returns: A pointerp
such thatp + i == &operator[](i)
for eachi
in[0,size()]
.
2. Complexity: constant time.
3. Requires: The program shall not alter any of the values stored in the character array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With