Jump to content
  • Advertisement

Archived

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

Viri-

Error Logging....

This topic is 6441 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 have been working on an error logger for my programs and have saved myself a lot of time. But now I need it to log multiple errors that occur in a text file. I''ve been using the basic fstream.h header and created a ofstream error_log; and used that to write any errors I have through out the program. But if I need to write more then one error to a line I can''t. How else could I do this? Here is my code: #include Void write_error(char *text); ofstream error_log; write_error("This is it being used…."); void write_error(char *text) { ofstream << "Error log file\n"; // line not displayed // because over written ofstream << text << ''\n''; // only line displayed. Last error // only one dispayed } thanks, Viri-

Share this post


Link to post
Share on other sites
Advertisement
Are there any C headers that would work with this or any other way to write multiple lines to a file?

Thanks,
Viri-

Share this post


Link to post
Share on other sites
If I''m understanding what you mean, you need to add ios::app to the open flags when you open the file, like so:

ofstream error_log( "errors.log",ios::out|ios::app );

this way, you won''t clear out the old contents of the file every time you open it. If that''s not what you mean, then you could also try bitwise OR''ing in ios::ate which will move the put pointer at the end of the file before every write. You may also want to use endl instead of ''\n'', since I believe endl is platform independent--machines like Macs use ''\r'' as the end of line marker.

Hope one of thise suggestions helps.

Liquid

Share this post


Link to post
Share on other sites
I think you need to put "<< flush" after your out statement. "endl" is roughly equivalent to "''\n'' << flush", I think, so it should work too, but I believe you can use "flush" to force a stream to finish writing without neccessarily having the newline. If you wanted to use several statements to write to one line in the test file, this would be useful.

--Tr][aD--

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!