PDA

View Full Version : printf vs. cout!



SirCrono6
01-04-2004, 07:18 PM
Personally, I like cout. What do you guys think?

- SirCrono6

DavidP
01-04-2004, 07:26 PM
I actually learned C++ before I learned C, so I prefer cout.

However, I have heard the printf is slightly faster. I am not sure if this is true or not, but it is what I have heard.

Still, cout is quite nice. A quick overload of the << operator can make it output pretty much anything. It is pretty nice.

I think if you are programming console, it doesnt really matter which you use. Not many people care about the miniscule difference in how fast text is outputted in console mode.

cout is not used very much in GUI programming, although I do use fstream's quite a lot. fstreams are VERY nice things to have. I love them.

ober
01-04-2004, 09:59 PM
I like printf..... because it's the only one I ever learned. I've taken 3 C classes and have never messed with C++ so far.

linuxdude
01-04-2004, 11:15 PM
cout is more like javascript. I like c's % thingy much more control and easier to output.

doubleanti
01-04-2004, 11:33 PM
>I like c's % thingy much more control and easier to output

Agreed. And if you wish you can apply this style formatting to buffer output if you are using a text setup that isn't the console (ie a graphics setup, that's what I used in AktiF). Though it takes a bit of work, it's worth this rather than redefining formatting yourself.

Salem
01-05-2004, 01:17 AM
Gee, this hasn't been done before (http://cboard.cprogramming.com/showthread.php?s=&threadid=43091&highlight=printf)

Rez
01-05-2004, 03:55 AM
cout or printf? None.

I like sprintf best :D cout & printf ain't cool for GUIs.

glUser3f
01-05-2004, 06:23 AM
when I do console stuff, I prefer printf, in fact, I always use C's stdio instead of C++'s iostream.

ygfperson
01-05-2004, 10:00 AM
cout has nifty type-checking. and you can define it for use with new objects you create, like string objects. anything you can do with printf can be done with cout using manipulators.

major_small
01-05-2004, 11:05 AM
I use cout because I don't know how to use printf... it looks like you can have more control over it, which would appeal to me if I actually bothered to learn how to use it...

Rez
01-05-2004, 11:26 AM
Hey is there any equivalent for sprintf() under C++?

Sang-drax
01-05-2004, 11:32 AM
Originally posted by DavidP
However, I have heard the printf is slightly faster. I am not sure if this is true or not, but it is what I have heard.
No, cout is faster than printf because cout has compile-time type-checking whereas printf has to parse a string.

Originally posted by DavidP
Hey is there any equivalent for sprintf() under C++?
std::stringstream in <sstream>

maes
01-05-2004, 11:45 AM
>>No, cout is faster than printf because cout has compile-time type-checking whereas printf has to parse a string.
didn't Sunlight proved that it's the other way around, or is my memory playing tricks on me?

Rez
01-05-2004, 11:56 AM
printf is faster than cout. You can try measuring the execution time between there and you'll see the big discrepancy, in favor of printf. cout sucks.

JaWiB
01-05-2004, 12:10 PM
I don't know how to use printf. All those %'s and whatever, I can't keep em straight.

SirCrono6
01-05-2004, 04:57 PM
>>Gee, this hasn't been done before

Sorry, I couldn't find it although I suspected it to be around =/.

- SirCrono6