I’m having bizarre behavior with stringstreams. It seems that if I create two stringstreams, one will write correctly and one will raise errors. (test is a char*)
ostringstream s;
ostringstream d;
s<<test<<endl;
d<<test<<endl;
This gives the message “error: invalid operands of types ‘int’ and ‘const char*’ to binary ‘operator<<‘” for the last line.
ostringstream s;
ostringstream d;
d<<test<<endl;
d<<test<<endl;
This gives the message “error: invalid operands of types ‘int’ and ‘const char*’ to binary ‘operator<<‘” for both lines writing to d.
The two streams should be identical, so I don’t know why d doesn’t work. Switching the order of the declarations of s and d doesn’t change anything. Anyone have an ideas why this might happen?
Thanks!
I have the same error when the variable
dhas already been declared so it has another type.