"qazmlp" <> wrote in message
news: om...
> I hope comp.lang.c will not find the following question as a
> complete off-topic.
>
> I would like to remove ie.comment out the 'cout' statements during
> compilation(actually preprocessing) time.
>
>
> The statements like this:
> cout<<"something\n" ;
> should be made as
> // cout<<"something\n" ;
>
>
> I tried for the following. But, It doesn't seem to be working.
>
>
> //--------START
> #ifdef DEBUG
> #define COUT std::cout
> #else
> #define COUT \/\/
> #endif
>
> int main()
> {
> COUT<<"HELLO\n"<<std::endl ;
> }
>
> //--------END
>
>
> If you can solve the above problem, please suggest a way for taking
> care of
> commenting out the 'cout' statements that spans in more than 1 line.
> eg:
>
> 12 COUT<<"HELLO\n"
> 13 <<"WORLD\n" ;
Maybe you could create your own stream and use that as cout, i.e
#if !defined(DEBUG) && defined(__cplusplus)
class MyStream : public std:

stream \
{ \
template <class T> \
MyStream& operator << (const T& obj) \
{ return *this; } \
}; \
#define COUT MyStream
#else
#define COUT std::cout
#endif
I'm not sure if the above code will work, I'm especially not too sure about
the template bit. And it most definitely would not work on c systems! Maybe
you could define cout to be an int and the << operator to be + , i.e
#if !defined(DEBUG) && !defined(__cplusplus)
int bogus_cout;
#define COUT bogus_cout=
#define << +
#elif !defined(DEBUG) && defined(__cplusplus)
class MyStream : public std:

stream \
{ \
template <class T> \
MyStream& operator << (const T& obj) \
{ return *this; } \
}; \
#define COUT MyStream
#else
#define COUT std::cout
#endif
But you would need to be 100% sure that the code in question does not use
the << _anywhere_. Hope this helps anyway!
S. Armondi