According to the top answer to this question, cout << expr
is equivalent to cout.operator<<(expr)
.
According to responses to this question, the statement above is untrue.
According to my own testing, cout.operator<<()
is the same as cout <<
when given an integer. When given a float, cout.operator<<()
coerces it to an integer. When given a string literal, as in cout.operator<<("hello world")
, it outputs what appears to be a memory address. And when given a variable holding a std::string, it gives a compiler error.
Could anyone give a beginner-to-intermediate-level explanation of what's going on?