printf vs cin

This may be a stupid question but I have to ask, is there a greater advantage to printf other than formatting I should be aware of? That is there something deeper?
They are used for different things.
printf is used to output text from the program.
cin is used to read input to the program.
Last edited on
I belive you meant printf vs cout. And yes, there are 2 things. FIRST: type safety. Prinf uses va_args, which can't possibly be good. Cout uses nested speciallized operators, which can't possibly be bad. SECOND: overloads. You can NEVER make anything like
1
2
3
4
5
6
7
8
9
10
11
struct //whatever
{
//whatwhateverever
} whatwhatwhatevereverever;

int main()
{
//whatwhatwhat... well, you get the point :)
printf("%blah", whatwhatwhatevereverever);
//whatwhatwhawhat... OMG why am I even doing this?!?!!?
}

but overloading the stream insertion/extraction is easy!
cout add 500kb to executable size, this is only disavantage I can think of over printf.
printf is hard coded to support the built in types.

C++ allows the creation of user defined types. And cout, well istream/ostream actually, allow I/O on user defined types.
Topic archived. No new replies allowed.