Phlana
Phlana

Reputation: 13

Inserting a vector into a vector of vectors

I am making a kind of insertion sort program that uses a vector of vectors. I want to know how I could insert a vector into a vector of vectors.

// constructing vector of vectors
vector< vector< int > > v_of_v;
for (int i = 0; i < 3; i++) {
    vector<int> row(2, i*100);
    v_of_v.push_back(row);
}

vector<int> tmp(2, 1);

// predetermined index
index = 2;

v_of_v.insert(index, tmp); // doesnt work

The examples I had seen just iterated through tmp and inserted each element of the vector which isn't what I was looking for. I want to be able to insert the vector itself, much like push_back can.

Upvotes: 1

Views: 2701

Answers (1)

code707
code707

Reputation: 1701

Try this :

v_of_v.insert(v_of_v.begin() + index, tmp); 

Upvotes: 2

Related Questions