Reputation: 4296
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?
Upvotes: 17
Views: 29132
Reputation: 3596
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)
Upvotes: 3
Reputation: 100748
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).
Upvotes: 26
Reputation: 79021
The new C++0x Standard defines another way of doing this:
http://en.wikipedia.org/wiki/C%2B%2B0x#New_string_literals
Upvotes: 18
Reputation: 400700
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()
.
Upvotes: 1