Advertisement Jump to content


This topic is now archived and is closed to further replies.


CLog << "text" ???

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m writing a logging routine, and I would love to just be able to do something like this:
CLog myLogger;
myLogger << "out put this text to logfile" << endl;
I''ve searched all over the net, but can''t find anything on doing this. All the tutorials I''ve found are about doing
cout << myLogger
but that is of no use to me. Can this be done or should I forget about overloading the << ?

Share this post

Link to post
Share on other sites
class CLog


CLog& operator<<(const std::string& string)
std::cout << "hmmn, what should I do with this string of length " << string.length() << " that I've got?\n";
return *this;



EDIT: change to same name as your class

[edited by - Enigma on January 25, 2004 11:58:22 AM]

Share this post

Link to post
Share on other sites
Sure, you can do that. Just define a suitable operator<<.

CLog& operator<<(CLog &log, const char *str)
{ log.Log(str); return log; }

Something like that. Note that it is not a member function
and it needs to call a member function of the CLog class
to do the actual logging.

Repeat for other data types (or go for a template if you wish).

[Edit]: Added a return.

Kami no Itte ga ore ni zettai naru!

[edited by - tangentz on January 25, 2004 12:20:09 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!