Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Programming

FORUM Dedicated to Programming
 
HomePortalLatest imagesSearchRegisterLog in

 

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

Go down 
AuthorMessage
Admin
Administrator
Administrator



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

What's the difference between... > printf() and cout? Empty
PostSubject: What's the difference between... > printf() and cout?   What's the difference between... > printf() and cout? I_icon_minitime14/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
http://programming.forumakers.com
 
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: