以前,我使用 STL 映射来执行上述任务。
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;
如何使用 CMap 执行相同的任务?
// How to make key sorted by string length?
CMap<CString, LPCTSTR, int, int> m;
最佳答案
你不能。来自 the MSDN documentation for CMap
:
You might think that this iteration is sequential by key value; it is not. The sequence of retrieved elements is indeterminate.
关于c++ - 按字符串长度对 CMap 键进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2467413/