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

五迷三道 提交于 2019-12-19 08:30:21

问题


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.


回答1:


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)



回答2:


This will work just fine:

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


来源:https://stackoverflow.com/questions/6603275/how-to-convert-defined-string-literal-to-a-wide-string-literal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!