c++ - vector 的 vector 会是连续的吗?

标签 c++ vector stl

<分区>

我需要分配一个行 vector ,其中 row 包含一个行 vector 。我知道 vector 是连续的。我想知道 vector 的 vector 是否也是连续的。下面给出示例代码

vector<long> firstRow;

firstRow.push_back(0);

firstRow.push_back(1);

vector<long> secondRow;

secondRow.push_back(0);

secondRow.push_back(1); 

vector< vector < long> > data;

data.push_back(firstRow);

data.push_back(secondRow);

内存中的序列会是0 1 0 1吗?

最佳答案

简而言之,没有。这是实际发生的事情:

enter image description here

关于c++ - vector 的 vector 会是连续的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19504455/

相关文章:

c++ -::std::regex_replace with syntax flag icase on Windows (VS2013 Update 4, VS2015 Update 3) 不匹配使用字符范围

c++ - 从 STL std::queue 中删除而不破坏已删除的对象?

c++ - 从文件中读取多态性

c++ - 从 CPP 文件中的 C 文件访问变量

algorithm - find_if 的两个条件

c++ - 检查迭代器属于哪个 vector

c++ - 关联容器 - C++ 中的异常而不是默认构造函数

c++ - 制作文件 : header including another header C++

c++ - 在 vector 中存储套接字然后关闭,不断添加相同的套接字

c++ - STL 映射的迭代器++ 复杂性