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...
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...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow ! What a quick response !
Moreover, it works !!!
Thanks! I thought '#' was only to introduce macros, but it looks like a magic operator :-)
Moreover, it works !!!
Thanks! I thought '#' was only to introduce macros, but it looks like a magic operator :-)
#define STRING(X) #X