map<string, vector <pair<int, int> > > pushing back into pair?

calccrypto picture calccrypto · Apr 13, 2011 · Viewed 7.5k times · Source

I have this map<string, vector <pair<int, int> > > variable and I'm pushing back a value, but code::blocks is telling me that pair does not have a member function called push_back. What should I do to get it to push back pairs rather than pair<>.push_back()?

This is basically what im doing:

map<string, vector <pair<int, int> > > T;
for(int x = 0; x < data.size(); x++)
     T[data[x].str].push_back(data[x].PAIR)

and the error is:

error: no matching function for call to 'std::vector<std::pair<int, int>,
  std::allocator<std::pair<int, int> > >::push_back(std::map<int, int, 
    std::less<int>, std::allocator<std::pair<const int, int> > >&)'

Answer

Elalfer picture Elalfer · Apr 13, 2011

Not sure about you problem.

Following code works fine for me:

map<string, vector <pair<int, int> > > T;
pair<int, int> p;
p.first = 1;
p.second = 10;
T["Hello"].push_back(p);
cout << T["Hello"][0].first << endl;