How to use << operator in 'continuous' mode and to determine the 'end' of sentence

I have the next class where I have defined << operator in order to debug my program. This class emit the results to a file, to a listbox, etc.

I have :
1
2
3
W_debug & W_debug::operator << (char * value) ;
W_debug & W_debug::operator << (int value) 
W_debug & W_debug::operator << (double  * value)

and the rest of types.

Ok, the implementation is the next :
W_debug & W_debug::operator << (char * value){
os<<value ;
return *this;
}

'os' is a stringstream private instance for W_debug. In this way, I can store data when I write :
W_debug()<<"hello "<<33<<a_double_variable;

Ok, the last line should produce hello 33 82.32 (but I dont know how to do it )

The question:
Imagine I have a log file, if I write at every <<, a 'file.write value' I'm going to have
hello
33
82.32

but what I want is:
hello 33 82.32

Now, the only way I've thought to solve it is to termiante the comand with an empty string.
W_debug()<<"hello "<<33<<a_double_variable<<"";
and :
1
2
3
4
5
6
7
8
W_debug & W_debug::operator << (char * value){
if (value =="")
file.write os;
os.clear;
else 
os<<value ; 
return *this;
}


I need some "magic" to know when I have the end of '<<' feeding.
That is to say: what I have to write to know that in the next case :
W_debug()<<"hello "<<33<<a_double_variable;
I have: hello, 33, a double_variable and 'no more' : just send the data to the ouput 'device'.

Any idea ? How can I detect that there is no more data using << operator ?
How can I detect the ";" end ? (magic ?)
I hope you understand the exposition of my problem.
Thanks.


Last edited on
Imagine I have a log file, if I write at every <<, a 'file.write value' I'm going to have
hello
33
82.32
Why is file.write adding a newline?
Solved.
I have to use the destructor ....
Topic archived. No new replies allowed.