字符串与宏串联 [英] string concatenation with macro
本文介绍了字符串与宏串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
用于在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"
推荐答案
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"
对于两个字符串:
#define CONCAT(a, b) (a"" b)
此处是链接到ideone上的演示的链接.
这篇关于字符串与宏串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文