W
winbatch
Hi,
I'm trying to play with classes and I'm having trouble with a
theoretical
problem.
I've create a 'Log' class, who creates and writes to log files. I was
able
to overload the << operator so that I could write to my log as follows:
Log logOne("log.txt", true, "\n" );
logOne<<"BLAH"<<"BLAH2";
In the constructor, the 'true' refers to having the log class write out
a
datetime stamp of each log entry, while the '\n' indicates how to
terminate
the log line.
The problem is that when I use the syntax about (<<"A"<<"B" ), etc, it
ends
up writing multiple lines because the << function is getting called
each
time. What I would like to do is have A and B be concatenated into one
string and then do the actual call to write the log line once. How do I
know
if I am the 'LAST' item being sent to the << so that I can store the
intermediate values and not write it out unless I am last?
Here is my function: (quite simple)
Log & operator << (string a)
{
writeLog(a);
return *this;
}
Thanks in advance...
I'm trying to play with classes and I'm having trouble with a
theoretical
problem.
I've create a 'Log' class, who creates and writes to log files. I was
able
to overload the << operator so that I could write to my log as follows:
Log logOne("log.txt", true, "\n" );
logOne<<"BLAH"<<"BLAH2";
In the constructor, the 'true' refers to having the log class write out
a
datetime stamp of each log entry, while the '\n' indicates how to
terminate
the log line.
The problem is that when I use the syntax about (<<"A"<<"B" ), etc, it
ends
up writing multiple lines because the << function is getting called
each
time. What I would like to do is have A and B be concatenated into one
string and then do the actual call to write the log line once. How do I
know
if I am the 'LAST' item being sent to the << so that I can store the
intermediate values and not write it out unless I am last?
Here is my function: (quite simple)
Log & operator << (string a)
{
writeLog(a);
return *this;
}
Thanks in advance...