It's so you'll be forced to put the console on the left the way god intended! :)
It actually has to do with something called operator overloading. If you're just learning C++ you probably haven't covered that yet so file what I'm about to say under "stuff I'll get later".
C++ lives on top of C. In C <<
and >>
are just bit shift operators. In c++ it can be more. std:cout << foo
is NOT C, it's C++. The reason it's C++ is because the std::cout
object overloads the <<
operator to mean something other than bit shifting.
In other words, <<
only means send foo
to cout
, because cout
said that's what it means. <<
is, in effect, a function on the class cout
.
It's almost as if you said std::cout->sendThatToMe(foo)
.
In this whole affair foo
is just a hapless parameter along for the ride that has no say over what <<
means. THAT is why you can't do it the other way. If you did it would be as if you were saying this:
foo->sendMeToThat( std::cout).
Which can be made to work IF you add that function (well the >>
operator really) to every stinking object you might ever want to send to the console. Oh and good luck pulling it off with primitives.
So while I think there are very good style reasons to want to keep the console stuff on the left there actually is a technical reason it has to be that way. It's because operators being overloaded are already left associative. They have been since they were used to shift bits in the old C days. Overloading them doesn't offer a chance to change their associativity.