2012-06-01 77 views

回答

1

运营商##连接两个参数让他们之间没有空格..

#define printe(a,b) a ## b 
    printe(c,out) << "testing"; 

输出是:测试

和单#用于参数替换枝条字符串参数 像

#define st(x) #x 
cout<<st(tesing); // equivalent to cout<<"testing"; 

和#也是一个预处理指令..

1

从描述维基百科页面的C preprocessor

的##运算符连接两个标记成一个令牌,如在这个例子中:其他

#define DECLARE_STRUCT_TYPE(name) typedef struct name##_s name##_t 
DECLARE_STRUCT_TYPE(g_object); // Outputs typedef struct g_object_s g_object_t; 

#的操作信号的指令,以C预处理器,例如:#include, #define, #undef, #error, #if, #ifdef, #ifndef, #else, #elif, #endif

+0

单身#怎么样?这两个运算符是否仅用于宏? – OneZero

+0

@ user1229490我更新了我的答案。是的,它们仅用于C和C++宏预处理器 –

0

'#'实际上不是运算符,它们是预处理指令,'##'仅用于函数宏定义。


已经有C许多预处理指令:

宏定义有:

#define 
#undef 

有条件的夹杂物,主要有:

#ifdef 
#ifndef 
#if 
#endif 
#else 
#elif 

用于行控制,有:

#line 

对于错误,有:

#error 

源文件包含,有:

#include 

对于编译指令,有:

#pragma 

对于更多信息,请阅读http://www.cplusplus.com/doc/tutorial/preprocessor/