Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

L"string"

Status
Not open for further replies.

TechResearch

Programmer
Oct 4, 2002
13
CO
What does the L before a string makes to it?
Does it set it to Unicode string?

I have a string strMyString,
and I have to pass it to a function that expects a L"string"
how do I convert strMyString to L"string"

I can't do
strMyString = L"string"
because I get this string from other function

any insights?

 
Yes, the L makes a string unicode. The type of the characters in a unicode string are wchar_t (which is supposed to be a distinct type, but some compilers think it's just an unsigned int). To deal with the string, you can use a C-style string of wchar_t (wchar_t *) and the functions in cwctype or wctype.h, or you can just use the wstring class, which is exactly like the "regular" string class except it holds wchar_t.
 
Thanks for the info,
looking through wchar_t documentation I found the functions mbstowcs and MultyByteToWideChar, they make the convertion to Unicode I was needing.

transforming sz to Unicode:

lenW = mbstowcs(NULL, sz, NULL);
wchar_t *d_Body = (wchar_t *)malloc(lenW * sizeof(wchar_t));
mbstowcs(d_Body, sz, lenW + 1);
 
I'd recommend using TCHARs- then it's both unicode and ansii compatible. There are tchar equivalents of all the string maniuplation functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top