I need to dynamically allocate an array of 5 vectors
of pairs
. This code snippet is supposed to add first elements to all 5 vectors
:
std::vector<std::pair<int, int>> * arr = new std::vector<std::pair<int, int>>[5];
for (int i = 0; i < 5; i++) {
arr[i].push_back(std::make_pair(i+1, i+11));
}
But it adds only 1 element to arr[0]
vector
for (auto el : *arr) {
std::cout << el.first << ", " << el.second << std::endl;
}
Printing out gives 1, 11
What I need is
1, 11
2, 12
3, 13
4, 14
5, 15
Please give me some hints. How to work with dynamic vector of pairs?
EDIT: Vector of vectors is one possible way. However, I want to use an array of vectors.