Possible Duplicate:
Which I/O library do you use in your C++ code?
I asked this question in a comment to another question, and I was asked to make it a proper question instead.
Why do I want to use iostream instead of stdio? More specifically, what do std::getline have to offer over the C equivalent?
Please, no language bashing.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With