如何#define的字符串为宽字符串文字转换? [英] How to convert #defined string literal to a wide string literal?

查看:410
本文介绍了如何#define的字符串为宽字符串文字转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/2192416/how-to-convert-concatenated-strings-to-wide-char-with-the-c-$p$pprocessor\">How要连接的字符串转换为宽字符与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"

(在的#define D字符串和 prepended,使之成为一个广泛的字符串)。

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

我试过这样:

#define MAKEWIDE(s) L##s

但这种生成 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)

这篇关于如何#define的字符串为宽字符串文字转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆