LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine);
printf("%s",s);
这里我收到输出计算机\ n只有我期待像电脑\网络\值输出。 为此提供解决方案..字符串串连的char *与LPCTSTR
LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine);
printf("%s",s);
这里我收到输出计算机\ n只有我期待像电脑\网络\值输出。 为此提供解决方案..字符串串连的char *与LPCTSTR
您尝试使用Unicode字符串cancat ANSI字符串。这是行不通的。或者使fisrt字符串ANSI
LPCSTR Machine="Network\\Value";
或使用MultiByteToWideChar()转换第二个字符串。
指向的字符串Machine是一个unicode字符串,因此在字符'N'后面有一个NULL字符。所以如果你使用非Unicode字符串concatanation你会得到这样的输出。你不应该混合这样的unicode和非unicode字符串。你可以这样做:
LPCTSTR Machine=L"Network\\Value";
TCHAR s[100]=_T("Computer\\");
_tcscat(s,Machine);
std::wcout<<s;
纯C90:
wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));
我知道,但我不能通过编码探索..如果你可以告诉我通过编码的解决方案..谢谢 – Rajakumar 2009-08-12 05:21:55
我只需要LPCTSTR和CHAR组合... – Rajakumar 2009-08-12 05:24:42
只有两个选项 - 如果其中一个字符串是恒定的(硬编码)你可以适当地声明它,否则你需要使用MultiByteToWideChar()进行转换。后者是在http://stackoverflow.com/questions/606075/how-to-convert-char-to-bstr/606122#606122中描述的,除了您可以使用malloc/free(或更好的新/删除)而不是SysAllocString/SysFreeString。 – sharptooth 2009-08-12 05:39:27