C / C ++宏字符串连接 [英] C/C++ Macro string concatenation
本文介绍了C / C ++宏字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#define STR1 "s"
#define STR2 "1"
#define STR3 STR1 ## STR2
是否有可能来连接有STR3 ==S1?
你可以通过传递args设置为另一个微距功能做到这一点。但有一种直接的方式?
Is it possible to concatenate have STR3 == "s1"? You can do this by passing args to another Macro function. But is there a direct way?
推荐答案
如果他们是两个字符串,你可以这样做:
If they're both strings you can just do:
#define STR3 STR1 STR2
在preprocessor会自动连接相邻的字符串。
The preprocessor automatically concatenates adjacent strings.
编辑:
如下所述,它不是preprocessor但也不串联编译器。
As noted below, it's not the preprocessor but the compiler that does the concatenation.
这篇关于C / C ++宏字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文