如何将LPCSTR字符串转换为LPCTSTR字符串

如何将LPCSTR字符串转换为LPCTSTR字符串

本文介绍了如何将LPCSTR字符串转换为LPCTSTR字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 LPCSTR 字符串转换为 LPCTSTR 字符串。我想连接两个字符串,当我尝试这样

i am trying to convert a LPCSTR string into LPCTSTR string. i want to concatenate two string,when i try like this

LPCTSTR str1 = L"Raja"
LPCSTR str2 = "Kumar"
wcscat_s(str1,(LPCTSTR)str2);

我发现o / p像Raja .... r(junkvalues).... how可以typecast LPCSTR LPCTSTR

i found the o/p like Raja....r(junkvalues)....how can typecast LPCSTR to LPCTSTR?

推荐答案

LPCTSTR 可以是纯字符或宽字符,具体取决于项目设置。此外,你不能连接一个宽字符串和一个纯char字符串。您需要将一个转换为兼容的形式(宽到多字节,反之亦然),然后连接。

LPCTSTR can be either plain char or wide characters depending on your project settings. Further, you cannot possibly concatenate a wide string and a plain char string. You need to convert one to a compatible form (wide to multibyte or vice versa) and then concatenate.

假设您希望目标是一个宽字符串,需要将Kumar转换为宽字符串。为此,请使用功能。

Assuming you want the target to be a wide string, you'd need to convert the "Kumar" to a wide character string. To do this use the MultiByteToWideChar function with appropriate code page.

查找这篇关于MSDN和John的链接的知识库文章。

Look up this KB article on MSDN and John's link.

这篇关于如何将LPCSTR字符串转换为LPCTSTR字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!