Link to home
Start Free TrialLog in
Avatar of vbremaud
vbremaud

asked on

Tricky question about macros...

Sorry for not being explicit, but you'll understand this question is difficult to sum up:

I want to write a macro that can replace abcd with "abcd" , that is transforming this line:
  cout << STRING(abcd);
with:
  cout << "abcd";

Please note that this absolutly needs to be a macro. So, no functions, no inline functions and so on.

thanks by advance :-)

PS: I have already tried:
#define STRING(X) "X"      // I knew it wouldn't work, but well... I tried it anyway
#define STRING(X) \"X\"    // It could have worked, but the compiler didn't agree for some reason...
Avatar of jkr
jkr
Flag of Germany image

Simply use

#define STRING(X) #X  
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbremaud
vbremaud

ASKER

Wow ! What a quick response !
Moreover, it works !!!

Thanks! I thought '#' was only to introduce macros, but it looks like a magic operator :-)