以前,我使用STL地圖來執行上述任務。按照字符串長度排序CMap關鍵字
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;
我很確定'CMap'實際上是一個哈希映射,因此不提供排序。 – GManNickG 2010-03-18 03:39:59