[英]push_back on 2D std::vector< std::vector<char*> > value made all the values are the same
[英]How to push_back values in the middle of a row of 2D array using std::vector?
我是std :: vector的新手,我的问题可能有一个非常简单的解决方案,但我不知道。 对于此代码,
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector <vector<int> > grid;
vector<int> col;
col.push_back(1);
for(int i = 0; i < 5; i++){
grid.push_back(col);
}
return 0;
}
这将使网格的第一列为1。如下所示:
1
1
1
1
1
有没有一种方法可以转到第二行并在其中添加几个零? 像这样?
1
1
1
1 0 0 0
1
grid.at(3)
为您提供grid
的第4个元素,即倒数第二行。 grid.at(3).push_back(...)
将添加到其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.