比较tchar []和char []

时间:2009-11-24 12:02:19

标签: visual-c++

如何比较两个值,如:

TCHAR s[100];
CHAR d[100];

两个变量都有一个值,那么如何比较这些值?

2 个答案:

答案 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); }