fstream and fopen difference?

  • Follow


Hi I wonder if someone can tell me the difference between using
fstream class and file handling functions like fopen fprintf. Which
one is faster in terms of writing? thanks.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply kate.z (1) 12/3/2003 11:19:49 AM

On Wed, 03 Dec 2003 06:19:49 -0500, kate wrote:

> Hi I wonder if someone can tell me the difference between using
> fstream class and file handling functions like fopen fprintf. Which
> one is faster in terms of writing? thanks.

fstream is in C++, and is a stream object for files, while fopen, etc...
are c library functions operating on file pointers. In general C functions
are much faster than their equivalent C++ stream equivalents, but I hope
that changes. I'm working on it, but a long way to go....


Regards,
-Dhruv.




      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
-1
Reply Dhruv 12/4/2003 12:48:37 AM


"kate" <kate.z@shaw.ca> skrev i en meddelelse
news:29efb34.0312021429.6857aa9a@posting.google.com...
> Hi I wonder if someone can tell me the difference between using
> fstream class and file handling functions like fopen fprintf. Which
> one is faster in terms of writing? thanks.

For formatted I/O, I would always use a stream. Streams are typesafe,
resilient in case an exception occurs and less verbose (you do not have to
close them explicitly).

Kind regards
Peter Koch Larsen



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Peter 12/4/2003 12:49:36 AM

In article <29efb34.0312021429.6857aa9a@posting.google.com>, kate 
<kate.z@shaw.ca> writes
>Hi I wonder if someone can tell me the difference between using
>fstream class and file handling functions like fopen fprintf. Which
>one is faster in terms of writing? thanks.

I think you are asking the wrong question. Speed, and relative speed are 
properties of specific implementations rather than C++ or C style i/o.

The real differences lie is such things as extensibility (much easier in 
C++ stream based code), type safety (much easier even for fundamental 
types) with streams, etc.

Note that input is always much harder than output because in the latter 
you have a good deal more control over the data. I have found it much 
easier to deal with adding a degree of validation of input to C++ 
streams than to the C file form.


-- 
Francis Glassborow      ACCU
If you are not using up-to-date virus protection you should not be reading
this. Viruses do not just hurt the infected but the whole community.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
-1
Reply Francis 12/4/2003 12:55:12 AM

On 3 Dec 2003 06:19:49 -0500, kate.z@shaw.ca (kate) wrote:

>Hi I wonder if someone can tell me the difference between using
>fstream class and file handling functions like fopen fprintf. Which
>one is faster in terms of writing? thanks.

I suppose, you are talking about "writing the source code", ie. "which
one is faster in terms of coding time".

That depends on the programmer. Probably he or she will be faster
using the style he is used to use. I suppose, for someone who is
trained in both ways, it will be faster to use the C++-style,
for its integrated type safety and for the adaptation to new
(own) data types.

Regards,
        Kurt.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
-1
Reply Kurt 12/4/2003 3:54:38 PM

4 Replies
772 Views

(page loaded in 0.069 seconds)

Similiar Articles:








7/22/2012 6:52:14 AM


Reply: