• Advertisement
Sign in to follow this  

String to file ends up in console window

This topic is 4681 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;
	Log->Write(temp.str());
}

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 {
private:
	std::ofstream log;		// the log file

public:
	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;}
};

#endif

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
Advertisement
Sign in to follow this  

  • Advertisement