Advertisement Jump to content


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


Making a function that can accept cout(<<) style parameters

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

Ok, so you''ve read the subject... How would you do it? For example I''d like to have a critical error function that can accept data like cout. After the function has it I''ll want to be writing it to a log file. Is this easy? Many thanks(for putting up with me... ) gimp

Share this post

Link to post
Share on other sites
#include <fstream.h> // at top of file

ofstream errorFile; // as a global"filename.txt"); // in game strtup code

errorFile << "This is going in the error file." << endl; // whenever you want to write error

errorFile.close(); // in shutdown game code

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Edited by - ncsu121978 on June 27, 2000 2:00:38 AM

Share this post

Link to post
Share on other sites
cout it not a function, it''s an object of a class (basic_ostream I think). That class has the << operator overloaded (called the insertion operator in this case, as you''re inserting the output variables into the stream). So if you want something that does this, you just have to write a class (or just instantiate an output file stream like in ncsu''s post) and overload the shifting operators (if those are the operators you want to use) to print or do whatever you want them to do.

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!