Archived

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

simple/stupid fstream help?

This topic is 5707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}
  

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites