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.
尝试这个 :
v_of_v.insert(v_of_v.begin() + index, tmp);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.