How to Push vector pair value in 2d vector?

110 Views Asked by At

Suppose I have a vector<pair<int,int>> v, the values are in v is {[1,3],[3,7],[8,9]}. I want to store them in vector<vector<int>> vv.

How can I do this?

I try to store them in vector<vector<int>> vv but I can't solve this

1

There are 1 best solutions below

0
Beyondo On

You can convert vector of pairs to vector of vectors by using a for-each loop.

for (auto& pair : v) // loop through 'each' pair inside the vector of pairs
    vv.push_back({ pair.first, pair.second }); // convert the pair to a vector and add it to the vector of vectors