Advertisement

simple/stupid fstream help?

Started by May 02, 2002 03:13 PM
1 comment, last by AbsolutDew 22 years, 10 months ago
Hey, i got class that''s suppose to log messages to a file, but for some reason when i call OpenIMLog, Log, and CloseIMLog and then check the file, it''s totally blank. It does create the file though in the /log directory, and i am checking for return values. What am i doing wrong?
  
class CIMWatch
{
  fstream m_fsLog;
  string m_strBuddyName;
  ....

public:

  // Opens the log file

  bool OpenIMLog();
  // Closes the log file

  void CloseIMLog();
  // Logs the contents of the buffer

  bool Log( string strText );
  ....
};

bool CIMWatch::OpenIMLog()
{
  string strLogName = "Logs\\" + m_strBuddyName + ".txt";

  m_fsLog.open( strLogName.c_str(), ios::app | ios::out );
  if( m_fsLog.fail() )
    return false;

  m_fsLog << "Opening " << strLogName << endl;

  return true;
}

void CIMWatch::CloseIMLog()
{
  if( m_fsLog.is_open() )
    m_fsLog.close();
}

bool CIMWatch::Log( string strText )
{
  if( m_fsLog.is_open() )
  {
    m_fsLog << strText;

    return true;
  }

  return false;
}
  
Which fstream header file are you using? Make sure it''s <fstream> (with no .h) Also, I recommend using std::ios_base::app and std::ios_base::out as your openmode flags.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
Advertisement
i am using just fstream and i tried the ios_base::app/out flags and still no go

[edited by - absolutdew on May 2, 2002 4:29:29 PM]

This topic is closed to new replies.

Advertisement