# macro operator

Prefixing a macro token with # will quote that macro token. This allows you to turn bare words in your source code into text tokens. This can be particularly useful for writing a macro to convert an enum into a string:
enum ColorType

// note the use of CT to stand for the enum value
// and #CT to create a string, such as "CT_RED"
#define CONV_CASE(CT) case CT: return #CT
std::string getString (ColorType t)
    switch ( t )
        CONV_CASE( CT_RED );
        CONV_CASE( CT_GREEN );
        CONV_CASE( CT_BLUE );
        default: return "unknown";



C preprocessor tutorial