So I was coding along working on another dll, I recompiled a dll containing the following code and suddenly my program was crashing, when i clicked the show info link on the 'send this report to Microsoft' dialog box, it said the dll which was throwing the error was msvcp90d.dll, I tracked it down to the log function (debigger said it couldn't be evaluated) :

#include "log.h" (includes <iostream>, <fstream>, <string> and has the log structure)

RupLogger::RupLogger()
{
	logfile.open("log.txt", ios::out);
}

RupLogger::~RupLogger()
{
	logfile.close();
}

void RupLogger::log(string msg)
{
	logfile << msg + " \n";
}

So I decided to try something, the logger started below is logged correctly, but log still crashes.

RupLogger::RupLogger()
{
	logfile.open("log.txt", ios::out);
	logfile << "[SYS] Logger Started \n";
}

So I thought there might be some strange issue with the logfile object's access or something so I tried below:

void RupLogger::log(string msg)
{
	this->logfile << "[SYS] Test Log \n";
	this->logfile << msg + " \n";
}

Now this is where it gets freaky, now the debugger jumps into the ostream header and says the following is not evaluating (in bold):

Line 746:

streamsize _Pad = [B]_Ostr.width()[/B] <= 0 || [B]_Ostr.width()[/B] <= _Count
		? 0 : [B]_Ostr.width()[/B] - _Count;

And um well now I'm just confused >.< and would like my program to run correctly again...

mvmalderen commented: Code tags on second post! +10

Recommended Answers

All 6 Replies

Well i copied your class, created a class definition out of whatever was given and used it and it worked fine for me.

#include <iostream>
#include <fstream>
#include <string>

class RupLogger
{
	public:
		RupLogger();
		~RupLogger();
		void log(std::string msg);
		std::ofstream logfile;
};

RupLogger::RupLogger()
{
	logfile.open("log.txt", std::ios::out);
}

RupLogger::~RupLogger()
{
	logfile.close();
}

void
RupLogger::log(std::string msg)
{
	logfile << (msg + " \n");
}

int main()
{
	RupLogger().log("Hi there");
}

Don't see any reason why it should crash. Could it be something else causing the crash. Did you check the core file?

Yea both ostream and the dll haven't been modified for months, and compiled and ran just fine a little while ago, what I don't get is why I'm getting the debug error inside of the ostream header file.

I am calling log through a pointer of the class, but it's been initialized and had it's constructor called before hand, besides if I put other functions in the log function it still runs correctly till it tries to write a line.

Here's an interesting development, it appears that its an external call which is causing the crash, if I call log from the constructor it works but why would a call from something else fail, let alone inside the frikken header! >.<

This is the code that crashes it and how it is being called. Now I'm kinda new but as far as I know I'm doing that right.

#include <iostream>
#include <fstream>
#include <string>

class RupLogger
{
	public:
		RupLogger();
		~RupLogger();
		void log(std::string msg);
		std::ofstream logfile;
};

RupLogger::RupLogger()
{
	logfile.open("log.txt", std::ios::out);
}

RupLogger::~RupLogger()
{
	logfile.close();
}

void
RupLogger::log(std::string msg)
{
	logfile << (msg + " \n");
}

static RupLogger* iLog;

int main()
{
	iLog = &RupLogger();
	iLog->log("Hi there");
}

Temporary object. Use new keyword.

iLog =new RupLogger();

doh! that makes sense thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.