Chinaunix首页 | 论坛 | 博客
  • 博客访问: 682843
  • 博文数量: 183
  • 博客积分: 9166
  • 博客等级: 中将
  • 技术积分: 1920
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-31 16:17
文章分类

全部博文(183)

文章存档

2010年(159)

2009年(24)

分类: C/C++

2010-03-29 21:04:16

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 what's before the ## with what's after it.

For example, the command

#define to_string( s ) # s

will make the compiler turn this command

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

into

 << "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

 << concatenate( x, y ) << endl;

into

 << xy << endl;

which will, of course, display '10' to standard output.

阅读(833) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~