3 ms·
A huge problem with cout and << is that setting flags (such as to print numbers in hex) is global and a destructive update. If you don't save the stream state
by phaedrus 7y ago
A huge problem with cout and << is that setting flags (such as to print numbers in hex) is global and a destructive update. If you don't save the stream state beforehand and restore it you change the flags for printing in unrelated code.
So making an object for printing probably helps with scope issues like that.
- rsynnott 7y agoYeah, I always wondered was << just an ill advised attempt to show off operator overloading (I’m sure things had it before C++, but it definitely wasn’t commonplace). It never made much sense to me.
- kabdib 7y agoThey were adding features to the language (e.g., "Koenig lookup") in the CFront era to accommodate iostreams. I was sad that they were spending a bunch of resources on that relatively useless stuff, rather than a sorely needed set of standard collection classes, not to mention a string class. And by "standard" I don't mean actual standards -- it was far too early in the game for that -- but even just enough to get by.
- dearrifling 7y agoADL is important for customization points in modern C++.