'C++ TCHAR to char conversion
How do you convert a TCHAR to a char array without using built-in functions and with out including other header files (how do you do convert TCHAR to char using standard c++ )
int main()
{
TCHAR szProcessName[MAX_PATH] = _T("<unknown>");
char szText[MAX_PATH] ;
std::cout << sizeof(szProcessName)/sizeof(TCHAR) << std::endl;
for (int i =0; i <sizeof(szProcessName)/sizeof(TCHAR); i++ )
{
szText[i] = (char)szProcessName[i];
}
//szText[sizeof(szProcessName)/sizeof(TCHAR)] = '\0';
std::cout << strlen(szText) << " " << strlen("<unknown>") <<std::endl;
std::cout << szText << " <unknown>" <<std::endl;
if (szText == "<unknown>")
std::cout << "equal" << std::endl;
else
std::cout << "Not equal " << std::endl;
return 0;
}
what i got in the console
$ g++ test.cpp && ./a.exe
260
9 9
<unknown> <unknown>
Not equal
Solution 1:[1]
I wrote my own function to compare two char arrays
int cmpstrs( char *x , char* y )
{
if (strlen(x) != strlen(y) )
return 0;
for (int i =0; i < strlen(x); i++ )
{
if (x[i] != y[i])
return 0;
}
return 1;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | manuel |
