views:

656

answers:

2

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);

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

+1  A: 

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.

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.

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

dirkgently
+1  A: 

See these notes: Unraveling Strings in Visual C++. The notes discuss the various kinds of strings you'll see in Microsoft C++ development and how to convert between them.

John D. Cook
thank you..cook
Rajakumar