what is the difference in printf and cout?

what is the difference in printf(" ");

and

cout << " ";

and why would you use one over the other
Last edited on
printf() is a leftover from C. ;)

std::cout is the C++ version, and I'd suggest using std::cout because among other reasons, you can overload the << operator to better support new types.

-Albatross
is scanf like cin then?
cout is more verbose (that can be good or bad, depending on who you ask)

cout is typesafe, printf isn't

cout works with std::strings, printf doesn't directly (you have to c_str your strings)

cout isn't threadsafe. I'm not sure if printf is, but cout certainly isn't.
I won't deny that those classes are perhaps overly complex. However, his rant about type-safety is unfounded, in my opinion, especially if you're just beginning programming with types.

-Albatross
Wow. That link's "why the FAQ is wrong" section is horrible. Clearly, that writing is biased and its analysis is incomplete. A few thoughts:

Finding errors at compile time, rather than at runtime, is money.

Consider containers of hetergenous, user-defined types and how they would be printed using printf.

I thought printf was an amazing function and it has a lot to do with the shell... but truth be told cout totally trumps printf simply because printf is just more complicated to use. cout was designed better.
Topic archived. No new replies allowed.