开发者

How to convert #defined string literal to a wide string literal? [duplicate]

This question already has answers here: 开发者_C百科 Closed 11 years ago.

Possible Duplicate:

How to convert concatenated strings to wide-char with the C preprocessor?

I have a string literal defined using a #define:

#define B "1234\0"

How do I use this definition to get this wide string literal at compile time?:

L"1234\0"

(just the #defined string literal with L prepended to make it into a wide string).

I tried this:

#define MAKEWIDE(s) L##s

but this generates LB.


Token pasting needs an additional level of indirection to deal properly with macros used as operands. Try something like:

#define PASTE(x, y) x##y
#define MAKEWIDE(x) PASTE(L,x)


This will work just fine:

#define B "1234\0"
#define LB L"" B
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜