
预编译语句中#与##的作用
1个回答
推荐于2018-04-12 · 知道合伙人软件行家
关注

展开全部
# 和 ## 操作符是和#define宏使用的. 使用# 使在#后的首个参数返回为一个带引号的字符串. 例如, 命令
#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;
解释为
cout << xy << endl;
理所当然,将会在标准输出处显示'10'.
#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;
解释为
cout << xy << endl;
理所当然,将会在标准输出处显示'10'.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询