Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wide string literals in c++ without putting L in front of each one

You'll have to forgive my ignorance, but I'm not used to using wide character sets in c++, but is there a way that I can use wide string literals in c++ without putting an L in front of each literal?

If so, how?

like image 955
Fry Avatar asked Nov 03 '08 21:11

Fry


People also ask

How do you declare a wide character in the string literal?

A wide string literal is a null-terminated array of constant wchar_t that is prefixed by ' L ' and contains any graphic character except the double quotation mark ( " ), backslash ( \ ), or newline character.

Is it possible to modify a string literal in C?

The only difference is that you cannot modify string literals, whereas you can modify arrays. Functions that take a C-style string will be just as happy to accept string literals unless they modify the string (in which case your program will crash).

Why is string literal Lvalue?

String literals are arrays - objects of inherently unpredictable size (i.e of user-defined and possibly large size). In general case, there's simply no other way to represent such literals except as objects in memory, i.e. as lvalues . In C99 this also applies to compound literals, which are also lvalues .

How do you escape a string literal?

String literal syntaxUse the escape sequence \\ to represent a backslash character as part of the string. You can represent a single quotation mark symbol either by itself or with the escape sequence \' . You must use the escape sequence \" to represent a double quotation mark.


1 Answers

No, there isn't. You have to use the L prefix (or a macro such as _T() with VC++ that expands to L anyway when compiled for Unicode).

like image 163
Ferruccio Avatar answered Sep 20 '22 18:09

Ferruccio