Are std::vector elements guaranteed to be contiguous?

前端 未结 7 2121
不知归路
不知归路 2020-11-22 03:41

My question is simple: are std::vector elements guaranteed to be contiguous? In order word, can I use the pointer to the first element of a std::vector as a C-array?

<
7条回答
  •  名媛妹妹
    2020-11-22 04:08

    cplusplus.com:

    Vector containers are implemented as dynamic arrays; Just as regular arrays, vector containers have their elements stored in contiguous storage locations, which means that their elements can be accessed not only using iterators but also using offsets on regular pointers to elements.

提交回复
热议问题