-1

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

fabian
  • 80,457
  • 12
  • 86
  • 114

1 Answers1

1

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
Beyondo
  • 2,952
  • 1
  • 17
  • 42