Can you expand #define's into string literals?
c++, c-preprocessor
Solution
This will do it:
#define NEW_LINE "\n" // Note double quotes
Printf("Output" NEW_LINE);
(Technically it's the compiler joining the strings rather than the preprocessor, but the end result is the same.)
Problem
Is there a way to get the C++ pre-processor to expand a #define'ed value into a string literal? for example: ``` #define NEW_LINE '\n' Printf("OutputNEW_LINE"); //or whatever ``` This looks to me like it should be possible as it's before compilation? Or is there a better design pattern to achieve this kind of behaviour (without resorting to runtime fixes like sprintf)? EDIT I understand that #define's can be evil, but for arguments sake... ADDITIONAL Does anyone have any criticism of this approach?