Auparavant, j'utilise la carte STL pour effectuer la tâche mentionnée.Trier clé CMAP par chaîne Longueur
struct ltstr
{
bool operator()(std::string s1, std::string s2) const
{
const int l1 = s1.length();
const int l2 = s2.length();
if (l1 == l2) {
// In alphabetical order.
return s1.compare(s2) < 0;
}
// From longest length to shortest length.
return l1 > l2;
}
};
std::map<std::string, int, ltstr> m;
Comment effectuer la même tâche avec CMap?
// How to make key sorted by string length?
CMap<CString, LPCTSTR, int, int> m;
Je suis assez sûr que 'CMap' est en fait une carte de hachage, et ne fournit donc pas d'ordre. – GManNickG