gpt4 book ai didi

c++ - wstring null 终止了吗?

转载 作者:可可西里 更新时间:2023-11-01 18:06:02 25 4
gpt4 key购买 nike

std::wstring 的内部结构是什么?包括长度吗?它是空终止的吗?两个?

最佳答案

Does it include the length

是的。它是 C++11 标准所要求的。

§ 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.

但是请注意,这是无法识别 unicode 的。


Is it null terminated

是的。 C++11 标准还要求 std::basic_string::c_str 返回 [0,size()] 范围内的有效指针,其中 my_string[my_string.size ()] 将是有效的,因此是一个空字符。

§ 21.4.7.1

const charT* c_str() const noexcept;
const charT* data() const noexcept;
1. Returns: A pointer p such that p + i == &operator[](i) for each i in [0,size()].
2. Complexity: constant time.
3. Requires: The program shall not alter any of the values stored in the character array.

关于c++ - wstring null 终止了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17939323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com