Jump to content
  • Advertisement
Sign in to follow this  

String to file ends up in console window

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

How come when I do this: (logging in class constructor)
Sdl_handle::Sdl_handle(int resolutionX, int resolutionY, int depth, cLog* LogFile) {
	Log = LogFile;	// store the adress to the logfile, if NULL is sent, no logs will be written

	// write to log
	std::stringstream temp;
	temp << "SDLasd: Screen resolution set to " << resolutionX << " x " << resolutionY;

It ends up on the console screen instead of in the log file? The Log class instance is owned by the same class as Sdl_handle is owned by. It looks like this: cLog.h
#ifndef _LOG
#define _LOG

#include <fstream>

class cLog {
	std::ofstream log;		// the log file

	cLog()	{
		log.open("Log.txt");			//Automatically deletes any existing file, you have to tell it to append for it not to.
		std::clog.rdbuf(log.rdbuf());	//Redirect clog to output to file.
	~cLog()	{log.close();};

	// log file function
	void	Write(std::string message) {std::clog << message << std::endl;}


If I write to the log in other functions (not the constructor) it works. :S Why?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!