How to expand a 2D vector?
for example, I defined an empty 2D vector
|
vector<vector<size_t> > PI;
|
now I want to expand this 2D vector to
Nx
rows and
Ny
columns one by one and assign different value for each;
How can I do this? using
push_back()
?
Last edited on
One approach could look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
vector<vector<size_t> > PI;
...
const size_t cur_y = PI.size();
PI.resize(cur_y + Ny);
for(size_t y = cur_y; y < PI.size(); ++y)
{
const size_t cur_x = PI[y].size();
PI[y].resize(cur_x + Nx);
for(size_t x = cur_x; x < PI[y].size(); ++x)
{
PI[y][x] = ...;
}
}
|
Topic archived. No new replies allowed.