Solved
Log like stringstream (stdlib)
Posted on 2006-10-27
I have a class for Logging called "Log". It has a method for writing to the log.... write(string).
Log mylog("c:\log.log");
mylog.write("This message will self destuct in 5 seconds...");
But when I want to pass a message which contains mixed vars, I do this
Log mylog("c:\log.log");
stringstream ss;
ss << "This message will self desctuct in " << countdown << " seconds");
mylog.write(ss.str());
but what I want to do is this:
Log mylog("c:\log.log");
mylog << "This message will self destrict in " << coundown << "seconds");
It would really tidy up my code.
I don't know enough about the << operator to be sure about what I'm doing.
Any pointers or a quick example?
Thanks!
Here is my Log.h
class Log
{
public:
Log(); // Log to console
Log(string filename); // log to file
~Log();
void write(string);
void warn(string);
private:
void waitForLock();
void unLock();
fstream *fp_stream;
CRITICAL_SECTION cs;
};