这两个符号很少被用到,不过很有意思。

#:转换成字符串

定义一个宏:

#define to_string( s ) # s


使用

cout << to_string(Hello World!) << endl;

相当于  cout<<"hello world"<<endl;

##:连接你想连接的

定义宏:

#define concatenate( x, y ) x ## y

使用

int xy = 10;
cout<<concatenate(x,y)<<endl;

即使未知的东西, ##也能给连接起来了,可见其变态之处。


相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2022-01-13
  • 2021-05-17
  • 2021-05-30
  • 2021-07-04
  • 2021-11-01
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-02-01
  • 2021-07-28
  • 2022-12-23
相关资源
相似解决方案