What does the 'L' in front a string mean in C++?

this->textBox1->Name = L"textBox1";

Although it seems to work without the L, what is the purpose of the prefix? The way it is used doesn't even make sense to a hardcore C programmer.


Solution 1:

It's a wchar_t literal, for extended character set. Wikipedia has a little discussion on this topic, and c++ examples.

Solution 2:

'L' means wchar_t, which, as opposed to a normal character, requires 16-bits of storage rather than 8-bits. Here's an example:

"A"    = 41
"ABC"  = 41 42 43
L"A"   = 00 41
L"ABC" = 00 41 00 42 00 43

A wchar_t is twice big as a simple char. In daily use you don't need to use wchar_t, but if you are using windows.h you are going to need it.

Solution 3:

It means that it is a wide character, wchar_t.

Similar to 1L being a long value.

Solution 4:

It means the text is stored as wchar_t characters rather than plain old char characters.

(I originally said it meant unicode. I was wrong about that. But it can be used for unicode.)

Solution 5:

It means it's an array of wide characters (wchar_t) instead of narrow characters (char).

It's a just a string of a different kind of character, not necessarily a Unicode string.