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.
This is a discussion on printf/cout within the C++ Programming forums, part of the General Programming Boards category; here is the que: Q:-what is the basic difference between cout and printf? i know printf is defined in STDIO.H ...
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++.![]()
"A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin
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.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Maybe printf is similar to wsprintf, which resides in user32.dll![]()
Studying programming languages,
you'll ALWAYS be a student ;-)
>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.
My best code is written with the delete key.