3 ms·
One thing that streams have that the c routines don't is type safety and overloading for user-defined output. Also take a look at cppformat for some of the bes
by GFK_of_xmaspast 11y ago
One thing that streams have that the c routines don't is type safety and overloading for user-defined output.
Also take a look at cppformat for some of the best of both worlds.
- vbezhenar 11y agoModern compilers are smart enough to catch type safety bugs for most printf use-cases.
- oppositelock 11y agoYup, cppformat is nice. I could also have a nice type-safe wrapper around libc functions. It doesn't change the fact that the API in the language is tedious. When you're doing internationalization, a common thing you might do is something along these lines: fprintf(fd, translate_string(context, "Result %d of %d"), num1, num2); The translation may be "%d of %d results" in another language. It's really difficult to map that into streams. Yes, I'm over-simplifying, since you can't have arbitrary placeholders due to order differences between languages, but it's _much_ harder to write simple code with streams than libc, and I stand by that! As for user-defined data, I've added .toString() functions on objects which I can call whenever needed, either from the ostream operator or pass the result to libc.