I switched to iostreams after I learned C++ 10 years ago. Several years ago I was convinced that it was a bad choice so I switched back. I did not regret the switch. For a good C++ programmer you need to know both.
Google C++ style guide prefers to use printf/sprint/snprint over iostreams. It says to use iostreams only for logging.
In terms of iostreams benefits:
- Type safety. Compiler (gcc) can detect type errors, as well as all static analysis tools. Even there is a type error, one can spot the error easily from the print out.
- Extensibility. Yes iostreams have overloading but all data members eventually go to POD types.
- No buffer overrun. Use snprintf to overcome the buffer size issue.
Now come the benefits of sprintf:
- Much better readability.
"Record(%d): %s\n"
is much easier to read than os << "Record(" << i << ") " << msg << endl;
- Performance. If you are doing a lot of iostreams stuff, changing them significantly improves performance. I once worked on a library that uses stringstream to convert int/doubles to strings. I replaced with sprintf and performance has improved a lot (there are a lot of calls to the conversion routine). For the record, boost::format has even worse performance.
My conclusion is that to use iostreams sparely. I use it to read memory buffer, or write to memory buffer occasionally. For other work, I use plain C function.