Reputation: 305
I want the following to be pushed in a vector, which data structure is suitable for the same: I want to push:
(1, 10)
(2, 11)
(3, 12)
I know how to push into a vector an integer but i am not sure about the list that i have now. I am looking for a data structure which is memory efficient. I know i can use a vector as well as list in this case, but which one is memory efficient. If there is any other data structure which is memory efficient then please suggest.
Upvotes: 1
Views: 116
Reputation: 55887
Some structure or std::pair<int, int>
.
#include <utility> /* std::pair<T1,T2> */
...
std::vector<std::pair<int, int>> vec;
vec.push_back(std::make_pair (1, 10));
vec.push_back(std::make_pair (2, 11));
for (auto iter = vec.begin(); iter != vec.end(); ++iter)
std::cout << iter->first << " " << iter->second << std::endl;
Upvotes: 8