<分区>
Possible Duplicate:
Are std::vector elements guaranteed to be contiguous?
std::vector 是否总是包含顺序内存地址中的数据作为数组[数字]?
<分区>
Possible Duplicate:
Are std::vector elements guaranteed to be contiguous?
std::vector 是否总是包含顺序内存地址中的数据作为数组[数字]?
最佳答案
对于除 bool 之外的所有类型,标准要求元素在内存中是连续的:
23.2.4/1 ... The elements of a vector are stored contiguously, meaning that if v is a vector where T is some type other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size()
请记住 std::vector<bool>
有特殊要求,与bool数组不同。
关于c++ - std::vector 与 array[number] 相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3077748/