I have this multimap built to map the hamming distance of a string to its corresponding string.
Since the hamming distance of two strings could be the same, I want them to be sorted in ascending order. However when I print it out, it is not sorted. The hamdistArray is declared as an unsigned type.
typedef multimap<unsigned, string, less<unsigned> > Check;
Check pairs;
pairs.insert(Check::value_type(hamdistArray[j], d.sortedWordDatabase[j]));
for(Check::const_iterator iter = pairs.begin(); iter != pairs.end(); ++iter)
{
cout << iter->first << '\t' << iter->second<< endl;
}
Elements in a multimap are sorted by the key (in this case the unsigned hamming distance). Elements with the same key are not sorted by the value (in this case the string), they are usually kept in the order in which they were inserted.