here is the que:
Q:-what is the basic difference between cout and printf?
i know printf is defined in STDIO.H and cout in IOSTREAM.H.
Printable View
here is the que:
Q:-what is the basic difference between cout and printf?
i know printf is defined in STDIO.H and cout in IOSTREAM.H.
Well for starters I believe cout is C++. ;)
cout is only in C++ because it's a class... there's an entire heirarchy of classes that it derives it's abilities from.
printf does it's thing without classes.
basically, if you're programming in C++, use cout. if you're programming in C, use printf. Some people will say printf is faster, and it is marginally faster, but that's not something you should take into consideration.
cout, being a derived class is more robust, AFAIK.
take all of the above with a grain of salt - I don't know all that much about printf.
Maybe printf is similar to wsprintf, which resides in user32.dll :)
>Q:-what is the basic difference between cout and printf?
The basic difference is that printf is a function and cout is an object. You pass a format string to printf that uses its own little language of format modifiers to tell printf the number and type of things you want to display. cout (usually) does the right thing by figuring out the number and types for you, so it's considered to be safer. Any sophisticated formatting with cout is extremely verbose compared to printf, but that's counter weighted by cout's flexibility. Provided you define the right member functions for your classes, you can use them with cout just like any other object that cout recognizes while it's not so simple with printf. cout, and iostreams in general, are bloated and slower than C-based I/O, but they're far more flexible.