Question

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?

Was it helpful?

Solution

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

OTHER TIPS

The new C++0x Standard defines another way of doing this:
http://en.wikipedia.org/wiki/C%2B%2B0x#New_string_literals

on a related note.. i'm trying to do the following

#define  get_switch( m )   myclass::getSwitch(L##m)

which is a macro the will expand

get_switch(isrunning)

into

myclass::getswitch(L"isrunning")

this works fine in c++ visualstudio 2008

but when i compile the same code under mac Xcode (for iphone) i get the error:

error: 'L' was not defined in this scope.

EDIT: Solution

#define  get_switch( m )   myclass::getSwitch(L ## #m)

this works on both vc++ and mac xcode (gcc)

Why do you not want to prefix string literals with an L? It's quite simple - strings without an L are ANSI strings (const char*), strings with an L are wide-character strings (const wchar_t*). There is the TEXT() macro, which makes a string literal into an ANSI or a wide-character string depending on of the current project is set to use Uncode:


#ifdef UNICODE
#define TEXT(s) L ## s
#else
#define TEXT(s) s
#endif

There's also the _T() macro, which is equivalent to TEXT().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top