【问题标题】:string concatenation with macro [duplicate]与宏的字符串连接[重复]
【发布时间】:2013-01-25 21:05:46
【问题描述】:

可能重复:
Macro for concatenating two strings in C

如何用宏连接两个字符串?

我试过了,但它没有给出正确的结果:

#define CONCAT(string) "start"##string##"end"

【问题讨论】:

    标签: c macros


    【解决方案1】:

    你需要省略##:adjacent string literals get concatenated automatically,所以这个宏会按照你想要的方式连接字符串:

    #define CONCAT(string) "start"string"end"
    

    对于两个字符串:

    #define CONCAT(a, b) (a"" b)
    

    这是link to a demo on ideone

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-29
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 2017-08-27
      相关资源
      最近更新 更多