【发布时间】:2019-05-14 17:22:57
【问题描述】:
如果你有一个 std::map 接受一个字符串和一个 int。
std::map<std::string, int> exampleMap;
如果你有正确的int,有什么方法可以打印字符串?
假设我将字符串“hello”和 int 0 插入到我的地图中:
exampleMap.insert(std::make_pair("hello", 0));
要打印 0,我们可以使用:
exampleMap.find('hello')->second;
有没有办法打印“hello”字符串?
【问题讨论】:
-
exampleMap.find('hello')->first也许? -
@πάντα ῥε 说什么?
-
假设我们只有整数可以帮助我们,我们不知道字符串。你能遍历一些整数,看看它们是否附加了一个字符串?
-
您需要迭代以找到具有正确“第二”的条目以打印“第一”
-
如果你问“你能不能遍历一堆 int,它们是映射中的值,并找出它们是否有匹配的键?”那么是的,你可以。
标签: c++ dictionary stdmap