#define 参数字符串化,但宽字符串 L " instead of "

#define argument stringized but to a wide string L" instead of "

本文关键字:字符串 of instead 参数 #define      更新时间:2023-10-16

我需要将#define参数字符串化为宽字符串。

所以虽然

#define c(x) x,#x

用作:

{c(maria),0,false},

给:

{maria,"maria",0,false} // maria is a member of an enum.

我不知道如何做同样的事情,但创建一个宽字符串。

我的意思是,与其说"maria"L"maria"

你可以做:

#define c(x) x,L###x

##串联对于将L和带引号的字符串组合到单个预处理令牌中是必需的(因为L字符串文本标记的一部分)。

#define c(x) x,L###x
c(Hello)

通过预处理器(带有 clang++ -E test.cpp )粘贴它得到:

Hello,L"Hello"

你为什么不试试

#define c(x) x,L#x

编辑:显然,这仅适用于Visual Studio。所以你应该按照其他人的建议去做L###x