惭愧, 今天测试了才真正明白, 在宏定义中使用"#",  还是因为群里有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

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2021-10-10
  • 2021-06-11
  • 2022-02-18
  • 2021-12-22
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-06-22
  • 2021-05-18
  • 2021-06-13
相关资源
相似解决方案