PDA

View Full Version : Which one will you prefer: cout or printf



Yoshi
11-03-2001, 04:44 PM
Which one is better?:rolleyes:
I prefer cout < printf:p

Hillbillie
11-03-2001, 06:36 PM
I have to say cout. I was raised on it...

dune911
11-04-2001, 03:44 PM
i prefer cout :)
i can't wait to use it again, learning c at the moment... *sigh*

Hillbillie
11-04-2001, 03:53 PM
>i can't wait to use it again, learning c at the moment... *sigh*<

C++ is backwards compatible with C, right? If you know C++, then you know C.

Unless, do you mean you're learning how to write programs entirely in C using no C++?

kimberleyp
11-07-2001, 12:32 AM
That depends on what you term 'knowing' a language. with C++, for instance, you are freed / shielded from some relatively low-level procedures, such as memory allocation and I/O. Although C also provides some functions for these, there are some things in C that a typical C++ programmer will not need to use - malloc() for instance.

Peter Kimberley
peter_kimberley@hotmail.com

bluehead
11-07-2001, 03:54 PM
it depends on what you are trying to use......If it is a simple game, i prefer using the putch(''); command, but it only outputs one variable. If your just outputting a message you want the user to know, use cout<<""; command. If you want a message at a sertian spot, use gotoxy(x, y); command and the cprintl(""); ((or whatever it is :) ). It just depends on what you are doing.

Xterria
11-07-2001, 07:37 PM
Well, you can do c by just using conio and stdio.h, and, instead of #include<stdio.h> its #include "stdio.h"...and you can't use classes. Thats really the only difference.

<<"command and the cprintl("");"

its printf() or if your using conio sprintf to copy a string to a variable, and cprintf() not cprintl

frenchfry164
11-08-2001, 07:20 PM
I like cout myself. You don't need to worry about \'s as much, and it looks neater. Also I think cout runs faster. sprintf() Might be the same, I never used it. I saw it in Andre Lamthe's Game Programming in 21 Days though ;)

starX
11-17-2001, 10:20 PM
printf() all the way... you gotta have the formating

maes
11-18-2001, 06:11 AM
>> printf() all the way... you gotta have the formating
same here. or maybe it's because I almost never used cout.

>>Also I think cout runs faster.
I think printf() is faster. I vaguely (very very very vaguely) remembered a discusion on the old board. and I think it was Sunlight who wrote a program to test it and printf() was faster.
(or was it the other way around, oh well)

CodeMonkey
11-19-2001, 03:09 PM
Printf: faster
Printf: Cleaner
Printf: Flexable
Cout<< slow
Cout<< easy
Cout<< grew up on it.

Close, but I say Printf.

Yoshi
11-19-2001, 07:36 PM
Now

printf() == cout << ;

:D :D :D

fanatic
11-21-2001, 10:01 AM
Only one thing.

Cout works also under graphics, (#include <graphics.h>), so quite better than some terrible outtextxy(...); <- parameter must be char* so it is'nt so simple typing some float or etc. in graphics
without cout (you must use smth. like ftoa(...) to transform it to char* and then use outtextxy(...))

PS: cin>> also works

Camilo
11-21-2001, 11:54 AM
printf is nicer, it formats the text for you, and I grew up with it.



Camilo

sean
11-29-2001, 04:15 PM
I've always wondered about the question in bold above... Anyway, back to the subject. I think people who are beginners at programming are going to vote for cout. Most course teach it first, and so they're more used to it. My first reaction when I saw the poll, was printf, because it's used in traditional function notation (as opposed to the overloaded extraction and insertion operatros used in cout), and I think simple things work better... but then of course I realized how they get the little extraction operators to work, so now I have no opinion, and I'm asking that same question..... What do you prefer? cout or printf();?

DeViLs_SouL
12-07-2001, 11:01 PM
this is a very common poll, however, i must say i always use both, but i like more printf, BUT cin is MUCH better than scanf. scanf really ........es me off. but i really like printf!...

lightatdawn
12-08-2001, 05:53 PM
I think printf() is faster. I vaguely (very very very vaguely) remembered a discusion on the old board. and I think it was Sunlight who wrote a program to test it and printf() was faster.
You are correct. I recall Sunlight getting quite upset on the subject... Not that it was an unusual state for him or anything. :) ... RANT: system(), cout, goto, DOS... you name it.

Printf is faster than cout by a fair margin. I dont use either now though as i've only created DirectX Apps lately.

-KEN-
12-09-2001, 12:38 PM
>>sprintf() Might be the same, I never used it

sprintf just copies on string over another...I wouldn't say it's faster thanprintf() because it does something totally different :p

Yeah, I :VERY: vaguely recall that...I use printf() when I do C/C+ DOS/Console stuff, anyhow so I didn't really care. I learned printf() first...ah, how I miss those late nights enthralled in C For Dummies :).

But I'm with lightatdawn. I haven't DONE console stuff in a long time...the only time I ever use it is if I'm testing out an algorithm that I'm putting in a larger windows app. But then again lately I've been C#-ing and creating my own OS (so I use my own write() function, now :p)

Yoshi
12-13-2001, 07:04 PM
What is the difference between printf(), sprintf() and putch()?
-----------------
Engineer223

dv916
12-21-2001, 01:29 AM
Even though I started learning C with printf(), i've gotten more comfortable with cout << for some reason.

face_master
12-23-2001, 12:48 AM
The book that I started C++ with used cout << so I have never used anything else. also, when I look at code which uses other thins, it looks all weird and hard to read/understand.

doubleanti
12-23-2001, 01:14 AM
printf, since you have v/s/printf and you can reroute a variable argument list... which means you can do formatted output with a different output... :)

Garfield
12-28-2001, 11:10 AM
printf...

I'm more comfortable with the formatted printing of printf.

And, no, C++ is not fully backwards compatible with C. When C++ branched of with OOP, C kept moving forward. I could give an example if you like.

--Garfield

klausi
12-30-2001, 11:00 AM
printf() is much better because you have to think more when you use it. You must always know what data type you have. This can prevent errors. You can also do something like this with printf():


char c='a';
printf("%d",c);

the output is the ASCII-code for 'a'. You cannot do it with cout.

klausi

Fordy
12-30-2001, 11:17 AM
printf() is much better because you have to think more when you use it. You must always know what data type you have. This can prevent errors. You can also do something like this with printf():

code:--------------------------------------------------------------------------------
char c='a';
printf("%d",c);
--------------------------------------------------------------------------------

the output is the ASCII-code for 'a'. You cannot do it with cout.

You can explicitely cast the char to a double like so;

cout << (double)c << endl;

As far as I know that's what printf is doing anyway

klausi
12-30-2001, 11:29 AM
But cout << isnīt compatible to C !

You can use your C++ compiler to program C-compatible code.
But if you only know senseless functions like cout << thatīs very difficult!

klausi

Fordy
12-30-2001, 11:34 AM
>>But cout << isnīt compatible to C !


Hmm....I cant remember saying it was :confused:

doubleanti
12-30-2001, 02:24 PM
>sprintf just copies on string over another...

it does formatted output to a string... i would say that is faster considering that outputting to the console is a slow job [because of the hardware updates]... whereas if it's just formatted output in memory, it's quick as can be... so i'd say that maybe sprintf is faster than printf... [don't confuse sprintf with being just a wrapper over printf because of the name... redirecting output has variations on speed depending on the media output...]

DarkDragon
12-30-2001, 03:34 PM
According to my compiler and profiler, cout is on average 5.75 milliseconds faster than printf. So much for that argument...

Garfield
12-30-2001, 05:14 PM
That's becuase printf is formatted printing. Note the formatting aspect. Time. Just means that you would have to do the formatting somewhere else in you C++ code.

--Garfield

doubleanti
12-31-2001, 12:53 AM
yes, i would hate having to DIY formatted output [redirection as well, thank the lord for vsprintf...]...

Justin W
01-01-2002, 04:03 PM
According to my compiler and profiler, cout is on average 5.75 milliseconds faster than printf. So much for that argument...

Hmm, printf() benches faster than cout on mine. (mingw32) I think the moral to this story is, that nobody really cares what you use as long as you are comfortable using it.

ygfperson
01-17-2002, 12:31 AM
i prefer cout for its simplicity, but its only there when im in c++.

master5001
01-22-2002, 04:48 AM
cout has quite a bit of overhead that printf doesn't have. And needless to say cout adds quite a bit of size to a file. I actually tend to use both a lot. I go with printf. In terms of ease I'd say that it is an undoubted tie. When it comes to speed, like I said cout has quite a bit of overhead. I found myself using sprintf more than both since I program windows most of the time.

dirkduck
01-23-2002, 12:05 AM
cout, was raised with it ;).

Credo
02-06-2002, 10:42 PM
I don't really have a favorite...they both get the job done. Unless your going to print and entire novel to the screen, speeds not much of an issue. If I had to choose one over the other I'd go with cout because its a little easier to use.