【发布时间】:2019-03-13 01:24:07
【问题描述】:
我在 Java 中有与此类似的代码,但让它在 C++ 中工作是另一回事。目前,此功能确实正确找到了密钥并将密钥推到我的向量后面。我想抓住键和它的一对值都被插入到向量的同一个索引中。我已经研究过使用一对作为我的向量,所以它会是(键,一对值),我不确定我是否能够做到。
vector<string> getIfPresentPartOfSpeech(multimap<string, pair<string, string>> dictionary, string name) {
vector<string> response;
auto it = dictionary.begin();
while (it != dictionary.end()) {
// Check if value of this entry matches with given value
if (it->second.first == name) {
// Yes found
// Push the key in given map
response.push_back(it->first);
}
// Go to next entry in map
it++;
}
return response;
}
【问题讨论】:
-
所以你想返回一个
vector<pair<string, pair<string, string>>>? -
响应应该是什么?你可以为它定义一个结构。你可以只做地图成员的确切类型——pair
> -
我正在研究定义结构。我考虑过做pair
>。也对我的其他选择感到好奇
标签: c++ dictionary vector