lang2
lang2

Reputation: 11986

C++ character constant notation

I'm seeing some character constant notation in C++ code that looks alien to me. Please educate me on this:

if (dc == L' '){

What does the L indicate?

Is it part of the standard?

Thanks,

lang2

Upvotes: 4

Views: 631

Answers (2)

Kerrek SB
Kerrek SB

Reputation: 477444

L is a literal specifier. For characters, it means wchar_t, so the type of L'a' is wchar_t. For strings, it means "array of wchar_t", so L"hello" is a wchar_t[6]. (And for integers, it means "long", so 1L is a long int.)

Upvotes: 12

Luchian Grigore
Luchian Grigore

Reputation: 258638

It's a macro literal specifier that transforms the character or character array to a wide character (or wide character array).

L'a' is the wchar_t equivalent of the char 'a'.

If you're used to windows development, it's equivalent to _T() if UNICODE is defined.

Upvotes: 5

Related Questions