store 2-D vector
How to store a 2D vector to another 2D vector using push_back?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void generation(vector< vector<char> > &world, vector< vector<char> > &world_copy)
{
vector <char> world1;
for (int i = 0; i< ROWS; i++)
{
for (int j = 0; j< COLS; j++)
{
world1.push_back(world[i][j]);
}
world_copy.push_back(world1);
world1.clear();
}
| |
Above is the code, I know it's wrong.
Why use push_back at all? If I understood your intent, you're looking for vector.insert
1 2 3 4
|
void generation(vector< vector<char> > &world, vector< vector<char> > &world_copy)
{
world_copy.insert(world_copy.end(), world.begin(), world.end());
}
| |
Topic archived. No new replies allowed.