Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无序映射迭代器差异问题_C++ - Fatal编程技术网

C++ 无序映射迭代器差异问题

C++ 无序映射迭代器差异问题,c++,C++,我有一个代码如下: #include <iostream> #include <unordered_map> #include <string> void foo(const std::unordered_map<char, std::string>& uom){ auto it2=uom.find('S'); if(it2!=uom.end()) //NEVER FORGET THIS std::

我有一个代码如下:

#include <iostream>
#include <unordered_map>
#include <string> 

void foo(const std::unordered_map<char, std::string>& uom){

    auto it2=uom.find('S');

    if(it2!=uom.end())  //NEVER FORGET THIS
        std::cout<< *it2 <<std::endl;
}
#包括
#包括
#包括
无效foo(常数标准::无序图和计量单位){
自动it2=计量单位查找('S');
if(it2!=uom.end())//永远不要忘记这一点

std::cout由
find
返回的迭代器是对键和值的迭代器,其形式为
std::pair
(在您的例子中是
std::pair
)。因此,为了访问与您查找的键相关联的值,您需要使用
it2->second
(即该对中的第二项)请参阅./p>中的示例代码。检查返回类型的文档<代码> STD::unOrdEdSMAP::FAND()/<代码>。具体地是迭代器类型。它不是你所想的。你得到的答案是解决问题的吗?如果是,请考虑它。