user119653
user119653

Reputation:

completely removing a vector c++

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

Upvotes: 0

Views: 820

Answers (1)

avakar
avakar

Reputation: 32635

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();

Upvotes: 4

Related Questions