Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

People also ask

What is L before string in C++?

L is the prefix for wide character literals and wide-character string literals which tells the compiler that the char or string is of type wide-char. w is prefixed in operations like scanning (wcin) or printing (wcout) while operating wide-char type.

What is the L prefix?

The L prefix denotes a wide character/string literal; i.e., it is of type wchar_t instead of char. Unicode based programs typically use wide strings, while ANSI/ASCII based programs typically do not.

What is the '\ of character in C?

\0 is zero character. In C it is mostly used to indicate the termination of a character string.

What is the C style character string?

A C-style string is simply an array of characters that uses a null terminator. A null terminator is a special character ('\0', ascii code 0) used to indicate the end of the string. More generically, A C-style string is called a null-terminated string.


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


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


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


It means that it is a wide character, wchar_t.

Similar to 1L being a long value.


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.


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.