网站定制与模板开发,软文发布网站,地方网站域名用全拼,oa办公系统软件在c/c的程序设计中#xff0c;有的时候不免要实现某些对象转换出相应名字字符串或两对象名直接相连的情况#xff0c;这时候可采用宏定义中加入#和##分别实现相应功能。下面是摘抄的一段解释。 The # and ## preprocessor operators are used with the #define preprocessor …在c/c的程序设计中有的时候不免要实现某些对象转换出相应名字字符串或两对象名直接相连的情况这时候可采用宏定义中加入#和##分别实现相应功能。下面是摘抄的一段解释。 The # and ## preprocessor operators are used with the #define preprocessor directive. Using # causes the first argument after the # to be returned as a string in quotes. Using ## concatenates whats before the ## with whats after it.
For example, the command #define to_string( s ) # s
will make the compiler turn this command cout to_string( Hello World! ) endl;
into cout Hello World! endl;
Here is an example of the ## command: #define concatenate( a, b ) a ## b
...
int xy 10;
...
This code will make the compiler turn cout concatenate( x, y ) endl;
into cout xy endl;
which will, of course, display 10 to standard output.