tags:

views:

416

answers:

1

Hi , I'm having problems removing a vector from a "multidimensional vector"

I would like to achieve this:

    1 1 1 1         1 1 1 1
    2 2 2 2         2 2 2 2
    3 3 3 3         4 4 4 4 
    4 4 4 4



 for example 

vector<vector<int>>vec;
    for i...//give vec values...
    vec[3].erase(vec.begin(),vec.end());

It seems like using vector.erase() or vector.clear() leaves an empty vector at the "third row" Is there a way to completetly remove that vector so that

vec[3]=4 4 4 4

Thanx for a great forum... /Bux

+4  A: 

The following line removes the third element of vec. If it had four elements, it will have three after the line is executed.

vec.erase(vec.begin() + 2);

The following line, on the other hand, will leave the third vector empty.

vec[2].clear();
avakar
But doesn't that leave an empty vector at the position 3?I've tried that in the code also.. perhaps my error is elsewhere if the 4th row becomes the third row doing this?
mrbuxley
Jepp I got it to work... once again I had one dimension too many in the code to easily find the error...thanks alot...
mrbuxley