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;
}
simple/stupid fstream help?
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?
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!
[ 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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement