假设我有 vector 的 vector
vector< vector<int> > bigTable;
vector<int> data;
data.resize(2);
fingertable.resize(5,data);
如何插入 vector ?
vector<int> newData;
newData.resize(2);
newData.push_back(123);
newData.push_back(456);
当我执行以下操作时,bigTable vector 中的数据仍然为 0。
bigTable.push_back(newData);
cout << bigTable[0][0]; // this will produce an output of 0
最佳答案
我认为您误解了 resize
的作用(也许您在考虑 reserve
?)。在您的第二个代码片段之后,newData
将包含 4 个元素:0
、0
、123
、456
。
关于c++ - 如何将 vector 插入多维 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10486236/