This item was added on: 2003/03/13
printf is a function that takes a variable number of arguments, the first argument being a format string explaining how to treat further arguments.
cout is an object of the
std::ostream class. The two are completely different in form, yet the result is the same, data sent to stdout.
This question is difficult to answer completely as often phrased since
printf are wildly different, but most often one of three questions are meant:
- Q: "Which is faster?" A:
printf, but the difference is too slight to worry about.
- Q: "Which is better?" A: Neither, it depends heavily on personal preference and what needs to be done.
- Q: "Which should I use?" A: You should use whichever you feel most comfortable with.
It is preferred that you use iostreams with C++ instead of the C functions because iostreams are type safe and extensible for user defined types, both of which are very good reasons.