Thread: why use iostream...

  1. #1
    Ultraviolence Connoisseur
    Join Date
    Mar 2004

    why use iostream...

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

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

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

    the latter compilers much why use the first one?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    cout will always do the right thing, because it is type safe
    cout << "the value is " << myfloat;
    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;
    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.

  3. #3
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    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