I am trying to solve this problem: http://stackoverflow.com/questions/268079/search-multiple-list-for-missing-entries. I used a multimap for duplication of keys. Here is my code:
#include <iostream>
#include <map>
#include <list>
#include <utility>
using namespace std;
int main(){
list<char>a;
list<int> b;
multimap<char,int>s;
a.push_back('A');
a.push_back('B');
a.push_back('C');
b.push_back(1);
b.push_back(2);
b.push_back(3);
s.insert(std::pair<char,int>('A',1));
s.insert(std::pair<char,int>('A',2));
s.insert(std::pair<char,int>('B',2));
s.insert(std::pair<char,int>('B',3));
s.insert(std::pair<char,int>('C',1));
s.insert(std::pair<char,int>('C',3));
list<char>::iterator it;
list<int>::iterator IT;
multimap<char,int>::iterator i;
for (i=s.begin();i!=s.end();i++){
for (IT=b.begin();IT!=b.end();IT++){
i=s.find(*IT);
if (i==s.end()){
cout<<(*i).first<< " "<<*IT<<endl;
}
}
}
return 0;
}
It compiled but after I run it it stops running abnormally. I think I am not accessing elements correctly. Please help me. EDIT: i have updated my code
#include <iostream>
#include <map>
#include <list>
#include <utility>
using namespace std;
int main(){
list<char>a;
list<int> b;
multimap<char,int>s;
a.push_back('A');
a.push_back('B');
a.push_back('C');
b.push_back(1);
b.push_back(2);
b.push_back(3);
s.insert(std::pair<char,int>('A',1));
s.insert(std::pair<char,int>('A',2));
s.insert(std::pair<char,int>('B',2));
s.insert(std::pair<char,int>('B',3));
s.insert(std::pair<char,int>('C',1));
s.insert(std::pair<char,int>('C',3));
list<char>::iterator it;
list<int>::iterator IT;
multimap<char,int>::iterator i;
for (it=a.begin();it!=a.end();it++){
for (i=s.begin();i!=s.end();i++){
for (IT=b.begin();IT!=b.end();IT++){
if ((*i).first==*it && ((*i).second!=*IT)){
cout<<(*i).first<< " "<<*IT<<endl;
}
}
}
}
return 0;
}
but here is too much combination then i need so what is problem?i think it should work correctly