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?
cout << expr
is equivalent ofcout.operator<<(expr)
" is not universally true. The answer from the 2nd question + 1st comment explain that. Not sure if that counts as duplicate... Perhaps this would help: #36809963 – Suffuse