如何比较两个值,如:
TCHAR s[100];
CHAR d[100];
两个变量都有一个值,那么如何比较这些值?
答案 0 :(得分:1)
在尝试比较之前,我会将两个值都转换为相同的类型。
BOOL UnicodeToAnsi(LPWSTR pszwUniString, LPSTR pszAnsiBuff, DWORD dwAnsiBuffSize){
int iRet = 0;
iRet = WideCharToMultiByte(
CP_ACP,
0,
pszwUniString,
-1,
pszAnsiBuff,
dwAnsiBuffSize,
NULL,
NULL
);
return ( 0 != iRet );
}
BOOL AnsiToUnicode(LPSTR pszAnsiString, LPWSTR pszwUniBuff, DWORD dwUniBuffSize){
int iRet = 0;
iRet = MultiByteToWideChar(
CP_ACP,
0,
pszAnsiString,
-1,
pszwUniBuff,
dwUniBuffSize
);
return ( 0 != iRet );
}
答案 1 :(得分:0)
如何使用lexicographical_compare和类似
的功能bool mycomp (TCHAR c1, char c2)
{ return tolower(c1)<tolower(c2); }
bool mycomp (char c1, TCHAR c2)
{ return tolower(c1)<tolower(c2); }