unordered_map不正确使用或错误
unordered_map used incorrectly or a bug?
嘿,我需要立即帮助...我通常使用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;
}
当我陷入这个问题时。在这里我试图使用 unordered_map<string, string>
,但是我会遇到一系列错误,我真的没有得到:
错误1错误c2039:'iterator_category':不是'std :: basic_string&lt; _ELEM,_traits,_ax>'c: program files(x86) microsoft Visualio 10.0 10.0 vc incless xutility 373 1 cpptp
和其他5个...正如我一个小时前只知道这些功能的那样,我假定它的错误用法或通过参考的呼叫不是仪式...因此
使用:
hashtable.insert(make_pair(name, customerPurchaseArray));
或:
hashtable.emplace(name, customerPurchaseArray);
或:
hashtable[name] = customerPurchaseArray;
请注意,有一个区别:前两个将不更改任何现有元素,而最后一个元素总是无条件地覆盖现有元素。
相关文章:
- 失败,出现错误 87:参数不正确.如何判断哪个参数不正确?
- 宏定义不正确没有错误
- rpmbuild check-rpath 报告错误,指出路径不是绝对的,不正确的
- 对从引用到 std::reference_wrapper 或编译器错误的隐式转换的理解不正确?
- "this" Lambda 捕获的是不正确的。海湾合作委员会编译器错误?
- 对分段错误的理解不正确
- 收到错误 87,安装程序的参数不正确DiGetDeviceInterfaceDetail
- Visual Studio 2017 在外部"C"中使用模板时出现不正确的错误
- 将 SFINAE 上下文中不正确的模板实例化的硬错误转变为软错误
- 测试整数是否在范围内时,逻辑错误和不正确输出
- 带有绝对路径的LoadLibrary返回不正确的HMODULE,没有任何错误
- unordered_map不正确使用或错误
- memcpy错误,长度不正确
- 此功能可能出现哪些错误或不正确?
- 由于转换错误而导致的过载/专业不正确
- 我正在尝试遍历 20x20 网格并计算产品,但总是得到不正确的结果。你能帮忙发现我的错误吗?
- LoadLibraryEx错误87(参数不正确)
- 错误:隐式删除,因为默认定义格式不正确(结构向量)
- 使用 qsort() 时对包含C++字符串的类进行不正确/错误的排序
- 没有错误,但输出不正确.可能存在指针问题