FORUM Dedicated to Programming
HomePortalCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 

 What's the difference between... > printf() and cout?

Go down 

Number of posts : 22
Age : 27
Registration date : 2008-11-12

PostSubject: What's the difference between... > printf() and cout?   14/11/08, 06:44 pm

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 cout and 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.
Back to top Go down
View user profile
What's the difference between... > printf() and cout?
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Programming :: C & C++ Programming :: C & C++ Frequently Asked Questions-
Jump to: