I'm using g++ compiler, and I want certain lines of my c++ code to be commented out or not commented, depending on my config.
I realise that I could do:
#ifdef DEBUG
cout << "foo" << endl;
#endif
But I would rather it all be on a single line:
#define DEBUG //
DEBUG cout << "foo" << endl;
...with DEBUG
being a macro for //
. But writing #define DEBUG //
yields nothing. Can anyone tell me what to do?
But I would rather it all be on a single line:
#define DEBUG //
People have given good examples of how to accomplish what you want, but no one has commented on why your approach didn't work.
Your approach will never work. It can't work. There is no mechanism for defining a macro that becomes a start of comment sequence for the simple reason that comments don't exist by the time preprocessor symbols are defined. They have already been stripped out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With