Does std::string need to store its character in a contiguous piece of memory?

前端 未结 3 1800
轻奢々
轻奢々 2020-12-11 14:35

I know that in C++98, neither std::basic_string<> nor std::vector<> were required to use contiguous storage. This was seen as an oversi

3条回答
  •  萌比男神i
    2020-12-11 15:04

    The C++11 standard, basic_string 21.4.1.5,

    The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <= n < s.size().

提交回复
热议问题