vendredi 18 janvier 2019

Use vector

This question already has an answer here:

I am trying to use vector<int> as a key to unordered_map. But it gives errors. I got some questions in the StackOverflow where vector<char> used as a key for the unordered_map.

But I am not sure how to change that for vector<int>. And moreover, the integer value range can be from 0 to 2000.

unordered_map <vector<int>, int>data;
int main()
{

vector<int>t;
t.push_back(2);
t.push_back(5);
data[t]=2;

t.clear();
t.push_back(1);
t.push_back(5);
data[t]=3;

t.clear();
t.push_back(1);
t.push_back(5);
cout <<data[t]<<"\n";
return 0;
}

Please help.

How can I use vector as a key of unordered_map without using Boost library?

Aucun commentaire:

Enregistrer un commentaire