chaîne concatenate char * avec LPCTSTR
-
13-09-2019 - |
Question
LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine);
printf("%s",s);
Ici j'ai reçu sortie Computer \ N seulement je pense comme sortie ordinateur \ réseau \ Value. Donnez solution pour cela ..
La solution
Vous essayez de cancat une chaîne ANSI avec une chaîne Unicode. Cela ne marchera pas. Soit faire la chaîne fisrt ANSI
LPCSTR Machine="Network\\Value";
ou convertir la seconde avec MultiByteToWideChar ().
Autres conseils
La chaîne machine pointue est une chaîne unicode et a donc un caractère NULL après le caractère « N ». Donc, si vous utilisez concatanation de chaîne non-unicode vous obtiendrez la sortie comme ça. Vous ne devriez pas mélanger les chaînes unicode et non unicode comme ça. Vous pouvez le faire comme ceci:
LPCTSTR Machine=L"Network\\Value";
TCHAR s[100]=_T("Computer\\");
_tcscat(s,Machine);
std::wcout<<s;
C90 pur:
wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow