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
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
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