[英]Unordered_map iterator throwing error
我有以下代码:
int solution(int K, const vector<int> &A) {
int count=0,size,comp=0;
unordered_map<long,long> map;
size = A.size();
if(size==0)
return 0;
for(int i=0;i<size;i++){
map[A[i]] = i;
}
for(int i=0;i<size;i++){
comp = K-A[i];
unordered_map<long,long>::const_iterator index = map.find(comp); //error here
if(index == map.end())
continue;
else{
count++;
}
}
cout << "final count: " << count << endl;
return count;
}
我收到无效操作数的错误,无法弄清楚我在做什么错。 我尝试过切换迭代器,但也可能是我的编译器。 我正在用它来编译:
lang ++ -stdlib = libc ++ -std = gnu ++ 11 workingpairs.cpp
我的错误是:预期';' 在声明末尾unordered_map :: const_iterator index = map.find(comp);
间接需要指针操作数('int'无效)__table _.__ insert_unique(* __ first);
在实例化功能模板专业化'std :: __ 1 :: unordered_map,std :: __ 1 :: equal_to,std :: __ 1 :: allocator>> :: insert'在这里请求
任何见解/帮助将不胜感激!
编辑:
我已经回过头并修复了错误。
您在以下声明中错过了::
unordered_map<long,long>const_iterator
应该:
unordered_map<long,long>::const_iterator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.