如何初始化 vector 的 vector ?
下面的代码使我的应用程序崩溃。
#include <iostream>
#include <vector>
int main()
{
std::vector< std::vector< unsigned short > > table;
for(unsigned short a = 0; a < 13; a++){
for(unsigned short b = 0; b < 4; b++){
table[a][b] = 50;
}
}
}
最佳答案
这将创建大小为 4 的 vector 的大小为 13 的 vector ,每个元素设置为 50。
using std::vector; // to make example shorter
vector<vector<unsigned short>> table(13, vector<unsigned short>(4, 50));
关于c++ - 初始化多维 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19940786/