3

私はこのmap<string, vector <pair<int, int> > >変数を持っていて、値をプッシュ バックしていますが、code::blocks はペアに push_back というメンバー関数がないことを示しています。ではなくペアを押し戻すにはどうすればよいpair<>.push_back()ですか?

これは基本的に私がしていることです:

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

エラーは次のとおりです。

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> > >&)'
4

3 に答える 3

6

あなたの問題についてはわかりません。

次のコードは私にとってはうまくいきます:

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;
于 2011-04-13T20:36:05.500 に答える