컴퓨터공부/C & C++ & STL

## preprocessor, string 합치기

achivenKakao 2009. 4. 9. 01:55

## preprocessor은 문자를 합치는 기능이있다.

ANSI 이전의 compiler에서는 아래 것을 이용하면 된다.

#define XPaste(s) s
#define Paste2(a, b) XPaste(a)b


+

#include <stdio.h>
#include <stdlib.h>

#define Paste(a, b) a##b
#define AB "ab"

#define XPaste(s) s
#define Paste2(a, b) XPaste(a)b
#define A "aaa"
#define B "bbb"


int main()
{
 printf("%s\n", Paste(A, B) );   // Paste에 보이는 그대로를 붙인다. 
 printf("%s\n", Paste2(A, B) );   // define 되어 있는 것을 붙인다.

 return 0;
}