Printf/scanf weren broken; why “fix” them with ugly shift operators?
The overloaded shift operator syntax is strange at first sight, but it quickly grows on you. However syntax is just syntax; the real issues are deeper. Printf is arguably not broken, and scanf is perhaps livable despite being error prone, however both are limited with respect to what C++ I/O can do. C++ I/O (left/right shift) is, relative to C (printf/scanf): • type safe — type of object being I/O’d is known statically by the compiler rather than via dynamically tested ‘%’ fields • less error prone — redundant info has greater chance to get things wrong C++ I/O has no redundant ‘%’ tokens to get right • faster — printf is basically an “interpreter” of a tiny language whose constructs mainly include ‘%’ fields. The proper low-level routine is chosen at runtime based on these fields. C++ I/O picks these routines statically based on actual types of the args • extensible — perhaps most important of all, the C++ I/O mechanism is Extensible to new user-defined data types (imagine the cha