Top reasons to use C++ streams with << and >>
- Faster (with a good compiler/library). The program doesn't have to parse a format string. The types to be printed are known compile-time, which gains speed.
- OOP. If I create my own class called BigInt, I can write my own operator<< and use it just like a normal int. This means decreased programming times, which means cash.
- Syntax equivalence.
Example: It's very easy to redirect output:
If I want to redirect the output to a file, for example, I only have to change one line of code.Code:ostream& out = cout; out << "rewr"; //.. out << var;
- Code readablilty. Code with << and >> looks alot nicer and cleaner: Info
But surely it must be OK to use *printf in such small example like this? No! Why learn a less useful way when there's a better way.
C++ is about OOP. If you don't like OOP, use C, but don't claim that your code is good C++ code, it's not. This is a C++ forum.