Archived

This topic is now archived and is closed to further replies.

csxpcm

confusing error message

Recommended Posts

hello everyone, I don''t understand this problem. The compiler reports an error, but I can''t fix it. Basically, in the header file, I include the line "ofstream logFile" I need my log file to output to a file. But I keep getting the following error. Any ideas anyone? I can''t see the problem! Any suggestions much appreciated, - Thankyou in advance, kind reagrds #pragma once #include <string.h> ... class CLog { public: CLog(); ~CLog(void); .... // the usual stuff private: .... ofstream logFile; <--- error message refers to this line }; This is the error message: c:\demo\Log.h(48): error C2079: ''CLog::logFile'' uses undefined class ''std::basic_ofstream<_Elem,_Traits>'' with [ _Elem=char, _Traits=std::char_traits ]

Share this post


Link to post
Share on other sites
yes, when i included that at the top of the file I received the following error.


/*
* Warning C4995, ''_OLD_IOSTREAMS_ARE_DEPRECATED'' is a deprecated name, is
* being issued because the old I/O Streams headers iostreams.h et al will no
* longer be supported from VC8. Replace references such as #include
* with #include <iostreams>, using the new, more conformant, I/O
* Streams headers.
*/


Fair enough, since I''m using VC8. However, even when i use
#include <iostream>

I still get an error message referring to the same line as before.
Thanks for the suggestion, but it still doesnt work :-(

Share this post


Link to post
Share on other sites
hehehe... i laugh because i also had the same problem once. i was knocking my head on the table, not seeing what''s wrong. then it hit me.

try:
std::ofstream logFile; 
that should fix it.

---
shurcool
wwdev

Share this post


Link to post
Share on other sites
quote:
Original post by csxpcm
damn, still no luck! this is driving me crazy!
but thanks for the tip anyway, ill keep trying. :-)


what i said didn't help? did it change anything? or do you still get exactly the same error message? that's weird...

here's my CLog class, see if you can get anything from it...

wwELog.h

  
#pragma once

#ifndef _wwELog_H_

#define _wwELog_H_

#include "wwEPrerequisites.h"

#include "wwEString.h"
#include "wwESingletonCleaner.h"

namespace wwE
{
#define MESSAGE_PRIORITY_INDICATION_CHAR '*'

enum LoggingLevel {
LL_LOW = 1,
LL_NORMAL = 2,
LL_HIGH = 3
};

enum LogMessageLevel {
LML_LOW = 1,
LML_NORMAL = 2,
LML_HIGH = 3
};

class CLog
{
private:
std::ofstream m_oLog;
LoggingLevel m_oLoggingLevel;
bool m_bDebugOutput;

inline char* MessagePriorityIndicator(LogMessageLevel oLMLevel, char *szBuffer);

public:
CLog(const String &sLogName, LoggingLevel oLoggingLevel = LL_NORMAL, bool bDebugOutput = true);
~CLog();

void LogMessage(const String &oMessage, LogMessageLevel oLMLevel = LML_NORMAL);
void LogMessage(LogMessageLevel oLMLevel, const char *szMessage, ...);
};
}

#endif // _wwELog_H_



wwELog.cpp

  
#include "wwELog.h"

namespace wwE
{
CLog::CLog(const String &sLogName, LoggingLevel oLoggingLevel, bool bDebugOutput)
{
printf("CLog created (%s, %i, %s).\n", sLogName.c_str(), static_cast<int>(oLoggingLevel), bDebugOutput ? "true" : "false");

m_oLog.open(sLogName.c_str());
m_oLoggingLevel = oLoggingLevel;
m_bDebugOutput = bDebugOutput;

// log the log creation

LogMessage(LML_HIGH, "log (name - '%s', logging level - %i) created", sLogName.c_str(), static_cast<int>(oLoggingLevel));
}

CLog::~CLog()
{
// log the log destruction

LogMessage(LML_HIGH, "log successfully finished");

m_oLog.close();

printf("CLog destroyed.\n");
}

void CLog::LogMessage(const String& sMessage, LogMessageLevel oLMLevel)
{
if (oLMLevel + m_oLoggingLevel >= 4)
{
tm *pFormattedTime;
time_t oRawTime;
char szBuffer[4] = {'\0'};

// figure out time

time(&oRawTime);
pFormattedTime = localtime(&oRawTime);

// display the message on the debugging screen, if asked to

if (m_bDebugOutput)
printf("%s (%i:%i:%i) %s\n", MessagePriorityIndicator(oLMLevel, szBuffer), pFormattedTime->tm_hour, pFormattedTime->tm_min, pFormattedTime->tm_sec, sMessage.c_str());

// log the message

m_oLog << MessagePriorityIndicator(oLMLevel, szBuffer) << " (" << pFormattedTime->tm_hour << ":" << pFormattedTime->tm_min << ":" << pFormattedTime->tm_sec << ") " << sMessage << "\n";

// to make sure the file is written to, instead of the buffer

m_oLog.flush();
}
}

void CLog::LogMessage(LogMessageLevel oLMLevel, const char *szMessage, ...)
{
// don't waste time if this message isn't going to be logged anyway

if (!(oLMLevel + m_oLoggingLevel >= 4))
return;

static char szBuffer[4097];
va_list oList;

va_start(oList, szMessage);
vsprintf(szBuffer, szMessage, oList);
LogMessage(szBuffer, oLMLevel);
va_end(oList);
}

inline char* CLog::MessagePriorityIndicator(LogMessageLevel oLMLevel, char *szBuffer)
{
for (int iLoop1 = 0; iLoop1 < static_cast<int>(oLMLevel); iLoop1++) {
szBuffer[2 - iLoop1] = MESSAGE_PRIORITY_INDICATION_CHAR;
}

for (; iLoop1 < 4; iLoop1++) {
szBuffer[2 - iLoop1] = ' ';
}

return szBuffer;
}
}


and these are my stream related standard includes (of course, most of them aren't used in the above example).

#include <fstream>
#include <iostream>
#include <iomanip>
#include <strstream>
#include <sstream> // for int or float to string conversions


[edited by - shurcool on July 30, 2002 6:18:07 PM]

Share this post


Link to post
Share on other sites