Are there any differences between file streams and FILE handles?

This is a discussion on Are there any differences between file streams and FILE handles? within the C++ Programming forums, part of the General Programming Boards category; I don't know if I've asked this question before, but, I assume FILE* is C and ifstream/ofstream is C++, but ...

  1. #1
    Shadow12345
    Guest

    Are there any differences between file streams and FILE handles?

    I don't know if I've asked this question before, but,
    I assume FILE* is C and ifstream/ofstream is C++, but is there any real advantage of using one over the other? Are there any major differences between the two that I should know about while writing projects that deal with file i/o?? If they are identical (as they basically seem to be) why were they both created?

    Thanks.

  2. #2

  3. #3
    Shadow12345
    Guest
    That's a cool site, thanks eibro.

    The biggest reason I saw on that site for using filestreams is that you can create your own streams using inheritance, which makes sense. That and the 'iostream' classes are less error prone to use

    Extensible: The C++ <iostream> mechanism allows new user-defined types to be I/O'd without breaking existing code. Imagine the chaos if everyone was simultaneously adding new incompatible "%" fields to printf() and scanf()?!).
    I'm not entirely sure what that means, 'without breaking existing code'? Maybe someone smarter can elaborate

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You can overload the >> and << for every single data type you'd like, and your streams are checked statically by the compiler.

    Imagine being able to add a %m field to printf() so you could print out your matrix class. Well, suppose someone else added an %m field as well; the ambiguty wouldn't be resolved by the compiler, as printf isn't typesafe and everything is checked dynamically.

    Unforseen consequences. That's how I interpret it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. A question about file streams.
    By Lawn Gnomusrex in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2008, 05:05 AM
  3. Need some help with file input streams
    By ProFiction in forum C++ Programming
    Replies: 5
    Last Post: 10-23-2005, 03:07 PM
  4. output file streams
    By neilman88 in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2003, 07:11 PM
  5. File Streams, new error on me.
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2001, 07:28 PM

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