The equivalence of cout << expr and cout.operator<<(expr) depends on the fact that expr .
If it lands as a "built-in" type that cout "knows", then yes, it is equivalent to cout.operator<<(expr) (member function).
If this is a "user type" (and here std::string ), then this is an overloaded non-member method with signatures similar to std::ostream& operator<<(std::ostream&, const std::string&); etc.
Why cout.operator<<("hello world") print a memory address?
The best member method is overloaded to the above (since it is forced to use a member method, this is ostream& operator<<(const void* value); which displays the value of the pointer (and not what it points to).
In contrast, cout << "hello world" causes a non-member overload of ostream& operator<<(ostream&, const char*) , and this in turn inserts each character into the output file.
Niall source share