#与##的用法

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

#:转换成字符串

定义一个宏:

#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;

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


原文地址:https://www.cnblogs.com/flysnail/p/2363142.html