Sign in to follow this  

String to file ends up in console window

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.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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this