There are several advantages, mainly with << and >> operators. Getting a string is not that different, although being able to read it in std::string is a significant advantage.
C ++ I / O has a security type. You do not write your parameter list as a quoted string, and then again as variables, etc. You write what you are going to print once, and C ++ determines how many parameters and what type they are. If you have type mismatches, CI / O can lead to incorrect I / O or even try to access protected memory.
C ++ I / O is easily extensible. You can easily write operator<<() and operator>>() as soon as you have a copy pattern. printf() and friends cannot be extended. You have a fixed list of format types.
C ++ I / O, while it looks pretty simple at the beginning, has a lot of structure available to programmers, so a good C ++ programmer can modify it to cover cases where CI / O cannot. (Do not abuse it.)
source share