Kinda like printf and cout . Whats the difference, except for the fact that printf is C and cout is C++. Same for scanf and cin .
Structs or classes?
To end this post, I say that structures and classes are the same thing basically, and structures are the newbie, old-fashioned C way, while classes are the grown-up, C++ way.
Kinda like printf and cout . Whats the difference, except for the fact that printf is C and cout is C++. Same for scanf and cin .
Kinda like printf and cout . Whats the difference, except for the fact that printf is C and cout is C++. Same for scanf and cin .
April 13, 2000 07:01 PM
Just to extend the post a little bit more =)
How many does realy prefer cout over printf?
I just can´t stand the syntax for cout..it´s not c syntax it´s something else....printf just looks better
//mats
How many does realy prefer cout over printf?
I just can´t stand the syntax for cout..it´s not c syntax it´s something else....printf just looks better
//mats
I think that question falls under the general blanket of what people are talking about in this topic. It''s a personal prefrence. Use whatever you like, unless your employed to do this and then go with what standards you are provided with.
Mike Barela
mbarela@earthlink.net
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
I like the streams syntax. There''s less redundancy, more type-checking, and it becomes easy to make my own streams and use them in the same way.
Actually, I like printf over cout since it looks like your old-fashioned function, not this new dang-fangled streaming magigy
But surely you overload operators at some point? It''s the same thing really.
Mike BarelaMikeB@yaya.com
My preference is printf over cout. It just seems easier to use (from a formatted output point-of-view) than cout''s interface. If you look at how you limit the length of outputed variables in cout you might agree with me. You only need to use a number in printf, instead of a function for cout. (At least, that''s what I think it is...it uses parentheses, anyway...)
About the type checking, I will say that cout is probably checked better than printf. At least in VC++ 6.0...I know that DJGPP, with all errors and warnings enabled, will complain if you use the wrong types for a given place in a format string. In VC++ I''ve gotten character strings printed through a decimal format (well, almost...it crashes the program at that point) without so much as a complaint from the compiler.
In any case, as with almost everything, it is personal preference.
About the type checking, I will say that cout is probably checked better than printf. At least in VC++ 6.0...I know that DJGPP, with all errors and warnings enabled, will complain if you use the wrong types for a given place in a format string. In VC++ I''ve gotten character strings printed through a decimal format (well, almost...it crashes the program at that point) without so much as a complaint from the compiler.
In any case, as with almost everything, it is personal preference.
I like printf better... no particular reason except that it just looks more like my other code. I also like to use sprintf, fscanf etc. because they all use the same format.
- Daniel
my homepage
- Daniel
my homepage
- DanielMy homepage
I prefer neither, since they won''t work properly in a windoze windowed proggie anyways .
Printf syntax is nice ''cause of
CString.Format()
and TRACE(),
stream syntax takes some getting used to but does the job equally well.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
Printf syntax is nice ''cause of
CString.Format()
and TRACE(),
stream syntax takes some getting used to but does the job equally well.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
Dragonskin: If DJGPP gives warnings on invalid printf fields, that''s quite neat, but obviously not part of the standard (technically, the function just asks for a const char*, what you put in it is your problem). Most compilers aren''t that smart (nor are they required to be).
Deakin and MadKeithV: I like to use streams because, just like fprintf, sprintf, printf, you can use them for many different purposes, not just console output. Thus, they can, and do, work under Windows.
//To write to the standard output:
cout << "Some text.";
//To write to a file
ofstream("file.txt") theFile;
theFile << "Some text.";
//To write to an in-memory location
stringstream theBuffer;
theBuffer << "Some text.";
When you learn one, you learn them all, pretty much. An extra point: the printf family is technically interpreted at runtime for the type information, whereas streams are fixed at compile time. This could result in faster execution.
Deakin and MadKeithV: I like to use streams because, just like fprintf, sprintf, printf, you can use them for many different purposes, not just console output. Thus, they can, and do, work under Windows.
//To write to the standard output:
cout << "Some text.";
//To write to a file
ofstream("file.txt") theFile;
theFile << "Some text.";
//To write to an in-memory location
stringstream theBuffer;
theBuffer << "Some text.";
When you learn one, you learn them all, pretty much. An extra point: the printf family is technically interpreted at runtime for the type information, whereas streams are fixed at compile time. This could result in faster execution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement