string concatenation with macro [duplicate]

大兔子大兔子 提交于 2021-01-27 07:11:41

问题


Possible Duplicate:
Macro for concatenating two strings in C

How to concatenate two strings with a macro?

I tried this but it does not give correct results:

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

回答1:


You need to omit the ##: adjacent string literals get concatenated automatically, so this macro is going to concatenate the strings the way you want:

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

For two strings:

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

Here is a link to a demo on ideone.



来源:https://stackoverflow.com/questions/14530395/string-concatenation-with-macro

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