why use iostream...

This is a discussion on why use iostream... within the C++ Programming forums, part of the General Programming Boards category; Why would you use iostreams when stdio functions compile so much smaller? such as cout << "hello, world!" << endl; ...

  1. #1
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    473

    why use iostream...

    Why would you use iostreams when stdio functions compile so much smaller?

    such as
    cout << "hello, world!" << endl;

    or
    printf("hello, world!\n");

    the latter compilers much smaller....so why use the first one?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    cout will always do the right thing, because it is type safe
    cout << "the value is " << myfloat;
    vs.
    printf("the value is %d ", myfloat );
    Some compilers can warn you that %d doesn't print a float, but many don't. The code will compile just fine, and may even produce some expected answers, but it is wrong.

    cout can use overloaded functions.
    cout << "The values in class are " << myclassvar;
    vs.
    printf( "The values in class are %?????? ", myclassvar );
    printf() cannot be extended in a portable way to output entire classes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    473
    I see, interesting.

    tell me salem, do you prefer to program in C or C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drieving from iostream
    By Thantos in forum C++ Programming
    Replies: 8
    Last Post: 06-23-2004, 04:57 PM
  2. iostream & hex?
    By dmlx90 in forum C++ Programming
    Replies: 0
    Last Post: 05-22-2002, 11:51 PM
  3. DJGPP Doesn't include IOSTREAM!!!!!!!!!!!
    By Frenchfry164 in forum Game Programming
    Replies: 12
    Last Post: 10-27-2001, 12:27 PM
  4. << in iostream
    By badman in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2001, 10:19 PM
  5. Is there a C iostream?
    By Khisanth in forum C Programming
    Replies: 1
    Last Post: 09-05-2001, 12:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21