Translations of this page?:

#和##

预处理操作符#和##和预处理指令#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

 
• • • SitemapRecent changesRSScc