Sign in to follow this  
sheep19

[ C++] file output error

Recommended Posts

sheep19    494
I want to implement a class Log for logging. Until now it has 1 function.
#ifndef MIN_LOG_H
#define MIN_LOG_H

#include <fstream>
#include <string>

namespace Min
{
	class Log
	{
	public:
		Log(const std::string &outputFilename) : out(outputFilename.c_str()) {}
		
		// reports an error occured in a function
		void FunctionError(const std::string &function,
								const std::string &msg,
								const std::string &action = "unknown");

	private:
		std::ofstream out;
	};

	static Log log("Min_Debug.txt");
}

#endif

// code file
#include "Min_Debug.h"

using namespace Min;
using namespace std;

void Log::FunctionError(const string &function, const string &msg, const string &action)
{
	out << "In function: " << function << endl
		<< "[" << msg << "]" << endl
		<< "Action taken: " << action << endl << endl;
}


int main()
{
log.FunctionError("main", "errr");
}


Nothing gets printed. What's wrong?

Share this post


Link to post
Share on other sites
SiCrane    11839
Well, I would guess that the problem lies somewhere in the FunctionError() function. Of course, that's only a guess because you didn't post its definition.

Share this post


Link to post
Share on other sites
sheep19    494
Quote:
Original post by Dolf
It actually printed to a .txt file on my pc. It worked...


Thanks. I was doing something wrong in another function.

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