字符串将 char* 与 LPCTSTR 连接起来

发布于 2024-07-30 17:12:30 字数 228 浏览 12 评论 0原文

LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine); 
printf("%s",s); 

在这里,我收到了输出 Computer\N 仅我期望像 Computer\Network\Value 这样的输出。 给出解决方案..

LPCTSTR Machine=L"Network\\Value";
char s[100]="Computer\\";
strcat(s,(const char*)Machine); 
printf("%s",s); 

Here i received output Computer\N only i expect output like Computer\Network\Value .
Give Solution for that..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒解孤独 2024-08-06 17:12:30

Machine 指向的字符串是一个 unicode 字符串,因此在字符“N”之后有一个 NULL 字符。 因此,如果您使用非 unicode 字符串连接,您将得到这样的输出。 你不应该像这样混合 unicode 和非 unicode 字符串。 你可以这样做:

LPCTSTR Machine=L"Network\\Value";
TCHAR  s[100]=_T("Computer\\");
_tcscat(s,Machine); 
std::wcout<<s;

The string pointed Machine is a unicode string and hence has one NULL character after the character 'N'. So if you use non-unicode string concatanation you will get the output like that. You should not mix the unicode and non-unicode strings like that. You can do it like this:

LPCTSTR Machine=L"Network\\Value";
TCHAR  s[100]=_T("Computer\\");
_tcscat(s,Machine); 
std::wcout<<s;
水溶 2024-08-06 17:12:30

您尝试使用 Unicode 字符串来转换 ANSI 字符串。 那是行不通的。 要么将第一个字符串设置为 ANSI

LPCSTR Machine="Network\\Value";

,要么使用 MultiByteToWideChar() 转换第二个字符串。

You try to cancat an ANSI string with a Unicode string. That won't work. Either make the fisrt string ANSI

LPCSTR Machine="Network\\Value";

or convert the second one with MultiByteToWideChar().

神回复 2024-08-06 17:12:30

纯C90:

wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));

Pure C90:

wcstombs(s+strlen(s), Machine, sizeof(s)-strlen(s));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文