LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[Re: [ILUG] C Vs C++]

[Re: [ILUG] C Vs C++]

Noel Carroll noel_carroll at usa.net
Mon Nov 29 17:27:32 GMT 1999


My view on the whole printf vs. cout thing is that stream.h provides derivable
classes.   I started off learning C++ by designing classes for my core
application processing and leaving the I/O to stidio based functions.   After
a bit I got into using the stream stuff and its a hell of a lot nicer in a C++
context.   Being able to overide operators << and >> allows you to populate
objects or output their contents to the stream in a very neat way.   You
couldn't do this as nicely with printf or any such stdio functions.   The
other aspect to the streams classes that nobody has mentioned, is the ability
to capture exceptions.   If you are going to need to do this then using
streams is a lot better than stdio.   

For instance, deriving a class from the ifstream and a field parsing class
will give you the ability to read in a file and parse it from your derived
class.  Its more awkward doing this using stdio and you have to come out of
the modular class structure to do that.

Using malloc instead of new is a great way to ensure that your base object
won't be instntiated if you're declaring a derived object.   Only new will do
this for you.   As said previously, you can override new to do what you wish
also.   The opposite goes for delete.   

Thats my 2 cents.

Noel

Kenn Humborg <kenn at research.wombat.ie> wrote:
On Sat, Nov 27, 1999 at 04:54:04PM +0000, kevin lyda wrote:
> Mel wrote:
> > cout instead of ifstream
> > fstream instead of fopen
> > new instead of malloc
> 
> i take this as libc's stdio vs. c++'s stl streams.  (i'm not a c++
> person, but my understanding is that there used to be a c++ lib -
> #include <streams.h> for example - and now there's the stl with #include
> <streams>)  one argument might be efficiency.  stdio has been studied a
> great deal and the idea has been to reduce data copying.  now how much
> studying has been put into making the stl efficient?  dunno.

You are mixing up the C++ Standard Library (the analog of the 
standard header files in ANSI C providing I/O, string support,
and other stuff) and the Standard Template Library (STL) which 
provides generic container, iterator and algorithm classes
such as lists, queues, maps, sorts, and other stuff.  STL 
uses C++ templates to provide type-safe support for any data
types.

C++ I/O streams are nothing to do with STL.

Mind you, as far as I'm concerned, << means left shift,
not "format in some hard-to-specify way for shoving up
an ostream".  But that's just a personal taste thing...

And the difference between #include <streams.h> and 
#include <streams> is that the .h version puts the 
definitions into the global namespace, whereas the
newer non-.h version puts them in the std:: namespace.

So if you do a #include <streams>, you'll have to do 
either 

   using std;
   cout << "hello, world\n";

or 

   std::cout << "hello, world\n";

Later,
Kenn



-- 
Irish Linux Users' Group: ilug at linux.ie
http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
List maintainer: listmaster at linux.ie


____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell