64,282
社区成员
发帖
与我相关
我的任务
分享
struct cmp_str
{
bool operator()(const TCHAR *a, const TCHAR *b) const
{
return _tcscmp(a, b) < 0;
}
};
typedef std::map<const TCHAR*, int, cmp_str> TESTMAP
const TCHAR* ch1 = new TCHAR[_tcslen(_T("one")) + 1];
const TCHAR* ch2 = new TCHAR[_tcslen(_T("two")) + 1];
const TCHAR* ch3 = new TCHAR[_tcslen(_T("three")) + 1];
const TCHAR* ch4 = new TCHAR[_tcslen(_T("four")) + 1];
const TCHAR* ch5 = new TCHAR[_tcslen(_T("five")) + 1];
_tcsncpy(ch1, _T("one"), (_tcslen(_T("one")) + 1) * sizeof(TCHAR));
_tcsncpy(ch1, _T("two"), (_tcslen(_T("two")) + 1) * sizeof(TCHAR));
_tcsncpy(ch1, _T("three"), (_tcslen(_T("three")) + 1) * sizeof(TCHAR));
_tcsncpy(ch1, _T("four"), (_tcslen(_T("four")) + 1) * sizeof(TCHAR));
_tcsncpy(ch1, _T("five"), (_tcslen(_T("five")) + 1) * sizeof(TCHAR));
TESTMAP mapper;
mapper[ch1] = 1;
mapper[ch2] = 2;
mapper[ch3] = 3;
mapper[ch4] = 4;
mapper[ch5] = 5;
/* do what you want */
delete []ch1;
delete []ch2;
delete []ch3;
delete []ch4;
delete []ch5;