简体   繁体   English

地图 <string, vector <pair<int, int> &gt;&gt;推回成对?

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

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. 我有这个map<string, vector <pair<int, int> > >变量,我正在推回一个值,但是code :: blocks告诉我该对没有一个名为push_back的成员函数。 What should I do to get it to push back pairs rather than pair<>.push_back() ? 我该怎么做才能让它回推对而不是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> > >&)'

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;

The message indicates that you are trying to push back a std::map , not a pair. 该消息表明您正在尝试推回std::map ,而不是一对。 What does your data structure look like? 你的data结构是什么样的?

Vectors do have push_back() method. 向量确实有push_back()方法。 Most likely data[x].PAIR is not of type pair. 最有可能的数据[x] .PAIR不是类型对。 What type is data[x].PAIR? 什么类型的数据[x] .PAIR? If you convert data[x].PAIR to pair it should work. 如果你将数据[x] .PAIR转换为配对它应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM