News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ Tips: IO - advantages of using streams over stdio

Started by ben2ong2, October 06, 2006, 11:17:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

PROBLEM: You are not allowed to view links. Register or Login (Bill Burris)

[...]

In my 3 years of using C++ I have stuck with the stdio library, because I
was more interested in getting some work done, instead of learning some
strange notation for doing things that worked perfectly well with printf,
sprintf, fprintf, etc.

[...]


RESPONSE: You are not allowed to view links. Register or Login (Anil Vijendran), 3 Dec 95

[...]

A few things I can remember off the top of my head may allure you...

1. Using fprintf means the knowledge about writing to a FILE is
   "hardcoded" in most of your code.  This can be avoided largely if
   you use iostreams.

2. You could design your own "stream" like thingies. For example, you
   could have a socket stream. If implemented properly, existing code
   that writes to a stream will work with your socket streams. You
   could even have streams that write to GUI windows and stuff.

3. Iostream is typesafe. You wouldn't get runtime errors by doing
   things like 

     int i = 10;   
     double d = 20.5;

     printf("i = %d f = %f", d, i);

4. With string streams, you don't have to worry about preallocating
   memory or having some arbit temporary limits like you have to do
   with sscanf.

5. You are not going to like C++ class libraries, if you don't learn
   iostreams. Most of them will provide support only for iostreams and
   not for stdio.


You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login