There is really no difference (from technical standpoint) between overloading any of those. As a matter of fact, even those are not special. They are simply overloadable operators - shift-left operator and shift-right operator. The reason to overload operators in general is to provide a better syntax, and the reason to overload those in particular is somewhat traditional based on perceived intuitivity.
Tradionally, operator <<
is overloaded to send something into something else (and called insertion operator), and operator >>
is overload to extract something from something else - and is referred to as extraction operator. In majority of cases, this something you are sending to is output stream
, such as std::cout
, and something you are extracting from is input stream, something like std::cin
. Having this in mind, std::cout << "Hello\n"
is easily understood as sending string "Hello\n" to output stream, which in case of std::cout
usually has an effect of printing it on the console window.
However, one could absolutely swap those overloads, and overload >> as an insertion operator. In latter case, printing would take form of std::cout >> "Hello\n"
. Wouldn't make any difference from compiler standpoint, but is less intuitive for programmers - those >> and << do resemble arrows.
Completely different operators could be chosen for this purpose. For instance, ->
is an overloadable operator too, and choosing it as an extraction operator would be great. Just consider this: std::cin -> str
. Arrow is even more explicit. Unfortunately, there is no overloadable operator <-
, so this lacks symmetry.
Also, one have to remember, that operator overloading was invented to allow C++ programms define new entities without introducing new reserved language constructs. If C++ was a completely fresh language, and would not stand on the shoulders of C, the end result would likely be very different.