开发者

How to concat LPCWSTR and char[]?

I am trying to concat a LPCWSTR and a char[] (and开发者_运维百科 get LPCWSTR as output).

How can I do that?


You are trying o concatenate a UNICODE string with an ANSI string. This won't work unless you convert the ANSI string to UNICODE. You can use MultiByteToWideChar for that, or ATL and MFC String Conversion Macros if you're using ATL or MFC.


You could convert your char[] array into a wide-char array using the following code (from MSDN)

wchar_t * wcstring = new wchar_t[strlen(array) + 1];

// Convert char* string to a wchar_t* string.
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, strlen(array) + 1, array, _TRUNCATE);

After that you can use wcscat_s to concatenate the converted character array to your original LPCWSTR.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜