Cerr output using cout

I came across a piece of code that does basically the following:

#include <iostream> using namespace std; int main() { cout << cerr << " Hi."; return 0; } 

Output:

 0x601088 Hi. 

First of all, why would anyone do 'cout <cerr' that doesn't make sense. Secondly, what is the meaning of the conclusion above?

It is worth mentioning that on my machine, the above code compiles and runs without errors.

However, much more complex code (doing the same thing as above) on another machine (connecting to the ssh server) running the same version of gcc 5.4.0 generates this error when executed (short for clarity):

 error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::ostream {aka std::basic_ostream<char>}') cout << cerr << "DB: Field " + e.table + "[" + e.index + "]." + e.field 

Any thoughts on this?

+7
c ++ iostream compiler-errors
source share
1 answer

Prior to C ++ 11, std::basic_ios suggested implicit conversion to void* . This code will not compile with C ++ 11 or later. You basically have this one that compiles with older versions of gcc:

 #include <iostream> int main() { void * x = std::cerr; std::cout << x << " Hi."; return 0; } 
+13
source share

All Articles