There are several advantages, mostly with the <<
and >>
operators. Getting a line isn't all that different, although being able to read it into a std::string
is a considerable advantage.
C++ I/O has type safety. You don't write your parameter list as a quoted string, and then again as variables and such. You write what you're going to print once, and C++ figures out how many parameters and what type they are. When you have type mismatches, C I/O might get the I/O wrong, or even try to access protected memory.
C++ I/O is easily to extend. You can write operator<<()
and operator>>()
easily, once you've got a sample to copy. printf()
and friends cannot be extended. You have a fixed list of format types.
C++ I/O, while it looks fairly simple at first, has a lot of programmer-accessible structure, and therefore a good C++ programmer can modify it to cover cases that C I/O can't. (Don't overuse this.)