I am trying to use a function to display (write or log or display) data for debugging my programs. The idea is to have a possibilty to send a message to 1 or more destinies without to do changes in the program.
I've got a simple solution, but i would like to make it simpler.
I'm sending a reduced version of my code.
Basically, i'm asking you help for solve the syntax error in line 25 (if we remove the slashes in line 25).
error: invalid initialization of reference of type
'std::ostringstream& {aka std::basic_ostringstream<char>&}'
from expression of type
'std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}'
note: in passing argument 2 of 'void dsplCln(int, std::ostringstream&)'
The return type of operator<< is ostream&, not ostringstream&.
keskiverto:
---------------------------------
Yes the error is like the one you showed.
I don't know how to make the convertion
let me try to explain:
// ( 1 ) adding (complex) info to ostringstream
buff_Os << "Previous " << iVal + 111; // normal assignation of data to a stream.
// ( 2 ) displaying the ostringstream using the function
dsplCln(2,buff_Os); // i can call the dspCln routine, with buff_Os without problem.
dsplCln (2, buff_Os << "Previous " << iVal + 111 << hlpDta <<endl );
/* if i remove the slashes from line 25, the compilador detect an error (the same you mencioned.
I was trying to do (on fly) both operations (1) - "load data" and (2) "send the buffer (ostringstream buff_Os) to 1 or 2, or ... "destination(s)" (please see line 8). The routine dspCln sends the message according with the value of the parameter dstny.
---------------------------------
dutch (1st reply):
Sound like the 2nd option. I really need to try the solution you give me.
---------------------------------
TheToaster.
I'm going to try the solution. Looks like fine!
---------------------------------