C++ 无序的地图使用不正确还是错误?

C++ 无序的地图使用不正确还是错误?,c++,iterator,unordered-map,C++,Iterator,Unordered Map,嘿,伙计们,我马上需要帮助。。。 我通常使用C语言,但是必须在C++中编写代码,所以很快就会用到有用的数据类型和过程。 代码如下: #include<iostream> #include <unordered_map> #include <vector> #include <string> using namespace std; void insertInHashtable(string customerString,unordered_ma

嘿,伙计们,我马上需要帮助。。。 我通常使用C语言,但是必须在C++中编写代码,所以很快就会用到有用的数据类型和过程。 代码如下:

#include<iostream>
#include  <unordered_map>
#include <vector>
#include <string>
using namespace std;

void insertInHashtable(string customerString,unordered_map<string, string> &hashtable )
{
    string customerPurchaseArray, name;
    int i= 0, firstCommaPosition = 0;
    int length = customerString.length();
    while (i<length)
        if (customerString[i] == ',')
        {
            firstCommaPosition = i;
            break;
        }
        else
            i++;
    customerPurchaseArray.assign(customerString, firstCommaPosition + 1, string::npos);
    name.assign(customerString, 0, firstCommaPosition - 1);
    hashtable.insert(name, customerPurchaseArray);
}

int main (int args[])
{
    string value = " error...!!!";
    unordered_map<string, string> hashtable;
    string customerString = "Ayush,p1234,p345,p34,p43,p444";
    insertInHashtable(customerString, hashtable);
    unordered_map<string, string>::iterator got = hashtable.find("Ayush");
    if (got != hashtable.end())
    value = got->second;
    std::cout<<value;
    char ch;
    std::cin>>ch;
}
#包括
#包括
#包括
#包括
使用名称空间std;
void insertInHashtable(字符串customerString、无序映射和哈希表)
{
字符串customerPurchaseArray,name;
int i=0,firstCommaPosition=0;
int length=customerString.length();
while(等秒;
std::coutch;
}
当我在这个问题上陷入困境时。。 在这里,我试图使用无序映射,但我得到了一系列错误,我真的没有得到像:

错误1错误C2039:“迭代器类别”:不是“std::basic\u string”c:\program files(x86)\microsoft visual studio 10.0\vc\include\xutility 373 1 CPPTP的成员

还有5个人。。。 因为我一个小时前才知道这些函数,所以我认为它的错误用法或引用调用是不正确的。。。 那么,是否有人知道问题是什么以及如何解决问题……任何建议都将不胜感激……

使用以下任一方法:

hashtable.insert(make_pair(name, customerPurchaseArray));
或:

或:


请注意,有一点不同:前两个不会更改任何现有元素,而后一个总是无条件地覆盖现有元素。

ohh…感谢一个抢夺者第一个工作了…但只是为了了解…我使用的方法实际上做了什么,这有什么不同…无序地图的值类型是std::pair,因此对insert的调用需要一个对。您没有在代码中创建对。无序的\u map::insert的两个参数重载都与您使用的参数不匹配。
hashtable.emplace(name, customerPurchaseArray);
hashtable[name] = customerPurchaseArray;