My class is like this:
class Outgoing
{
multimap<string,string> outgoing;
public:
void makeConnection(string key, string value)
{
outgoing.insert(pair<string,string>(key,value));
}
void iterate()
{
multimap<string, string>::iterator it;
multimap<string, string>::iterator it2;
pair<multimap<string,string>::iterator,multimap<string,string>::iterator> ret;
for (it = outgoing.begin();it != outgoing.end();++it)
{
ret = outgoing.equal_range((*it)); ??????
for (it2=ret.first; it2!=ret.second; ++it2)
{
???????
}
}
}
};
background:
I want to represent a graph which can have many nodes. The key won't repeat but can have multiple values.
str1 ----> val1
str1 ----> val2
str2 -----> val3
I want to know how can I get number of values for a particular key? for e.g. in the above question , for str1 it will be 2?
As you can see , I tried to do something after some digging around but in vain.
What is wrong with my code?
thanks
EDIT ::: after templatetypedef's comment, I edited the code to:
for (it = outgoing.begin();it != outgoing.end();++it)
{
cout<< (*it).first << " "<< outgoing.count((*it).first);
}
I can get the count, but the key("str1") comes twice. So the answer I see is 2 2 1.
I would appreciate it very much, if somebody teaches me how to iterate in such a way I get only one key. BTW, thanks, templatetypedef