I'm not sure if this is even possible. All of the operator<< examples I've seen so far just allow cout to recognize new classes...
What I am trying to do is basically write my own sort of cout object to print to screen, files... or specially format the data. But I want to still be able to use cout the way it normally works. Here is an example of what I would like to do:
...
cout << "Print normal text." << endl;
myCout << "Only print this if a debug flag is set." << endl;
...
I know that I could wrap all my conditional cout's in an #ifdef DEBUG block, but I'd like it to look cleaner like above.
This is what I thought I could do, but I'm getting a lot of compile errors with it...
class myCout
{
public:
ostream& operator<<( ostream& out, myCout& me );
};
If anyone has any suggestions, I'd really appreciate them.
Thanks,
Chris.
What I am trying to do is basically write my own sort of cout object to print to screen, files... or specially format the data. But I want to still be able to use cout the way it normally works. Here is an example of what I would like to do:
...
cout << "Print normal text." << endl;
myCout << "Only print this if a debug flag is set." << endl;
...
I know that I could wrap all my conditional cout's in an #ifdef DEBUG block, but I'd like it to look cleaner like above.
This is what I thought I could do, but I'm getting a lot of compile errors with it...
class myCout
{
public:
ostream& operator<<( ostream& out, myCout& me );
};
If anyone has any suggestions, I'd really appreciate them.
Thanks,
Chris.