
























惭愧, 今天测试了才真正明白, 在宏定义中使用"#", 还是因为群里有TX提出, 才测试的
看代码:
#define macro(a) #a
#define macro2(a,b) a##b
#define macro3(a,b,c) a##b##c
#a, 表示a不再是一个变量, 而变成了字符串"a"
##表示连接, a##b, 表示输入的参数名为ab, a##b##c同理, 代表变量名为: abc
测试例子:
int x = 3;
int y = 4;
int xy = 10;
int xyz=20;
CString str;OutputDebugString(macro(x));
str.Format(
"%d",macro2(x,y));
OutputDebugString(str);str.Format(
"%d",macro3(x,y,z));
OutputDebugString(str);
输出结果为:
x
10
20
第一个为x, marco(x), x变成了"x"字符串
第二个为10, macro(x,y), 就是变量xy
第三个为20, macro(x,y,z), 就是变量xyz
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhucde/archive/2011/01/09/6125069.aspx
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。