我们定义宏如下:

1 #define P(E)  cout<<#E<<'='<<E<<endl

 

在后面的字符序列中,我们看到参数E前面带了个‘#‘,这样写的效果是:将参数E字符串化

 

测试程序如下:

#include <iostream>
using namespace std;
#define P(E) cout<<#E<<'='<<E<<endl
int main()
{
           P(1+2);
           return 0;
}

结果如下:

字符串化的预处理器特征

 

 

 

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2021-10-08
  • 2021-08-26
  • 2022-02-08
  • 2021-07-28
  • 2022-12-23
猜你喜欢
  • 2021-04-22
  • 2022-02-11
  • 2022-12-23
  • 2022-01-10
相关资源
相似解决方案