230
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.

3
  • 7
    You are not using C++. It is optional in a C++/CLI program if the string literal only contains ASCII characters. The compiler automatically converts it to a utf-16 encoded string that's interned either way. Jun 17, 2011 at 12:29
  • 20
    @Hans: "You are not using C++" How do you know? Jan 31, 2017 at 20:22
  • @LightnessRacesinOrbit: textBox1 is a typical .NET name for a TextBox that was dragged and dropped onto a Form. Nov 21, 2022 at 11:14

7 Answers 7

186

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

1
137

'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.

3
  • 45
    note: it's not necessarily 16 bit. It's OS specific.
    – batman
    Oct 4, 2014 at 20:33
  • 5
    I think that in linux wchar_t is 32 bits
    – user10607
    Dec 13, 2015 at 10:00
  • 24
    "In daily use you Don't need to use wchar_t" is arbitrary jugement. As a non native English speaker, I can say that I must use it all the time...
    – Heyji
    May 27, 2019 at 19:48
22

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

0
21

It means that it is a wide character, wchar_t.

Similar to 1L being a long value.

17

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.

12

L is a prefix used for wide strings. Each character uses several bytes (depending on the size of wchar_t). The encoding used is independent from this prefix. I mean it must not be necessarily UTF-16 unlike stated in other answers here.

2

Here is an example of the usage: By adding L before the char you can return Unicode characters as char32_t type:

          char32_t utfRepresentation()
      {
                if (m_is_white)
                {
                          return L'♔';
                }

                return L'♚';

      };

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.