Jump to content
  • Advertisement


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


Replacing cout

This topic is 6823 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

Hi, One of the really nice features of c++ IMHO are iostreams. Just define the << operator and voila, you can outut you object to the console or files etc. The problem is what if I wanted to replace cout in the first place? What if I wanted to do say, coutGL << "Lalalala" << endlGL; to output to an OpenGL scene, how could that be accomplished? This is not a GL question... I''m interested in overloading?/ inhereting from? cout. Thanks, OberonZ ---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.

Share this post

Link to post
Share on other sites
Im not sure about the overloading inheriting part of cout, but you could try this. Just make a class that has your output routines and contains an operaotor overload of << and has what you want to do with it through the function implementation.

class foo
friend ostream& operator<<(whatever params you need)

Then code the function body in the .cpp file for your class. Since it is a friend function, when you add the body omit the foo:: part of it. The just instantiate an object of your class and when ever you use the << on a member of that class your overloaded << will get called.

Mike Barela

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!