reading and writing to files in windows

This is a discussion on reading and writing to files in windows within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, I am writting a windows app that read and writes files using the common dialog boxes for opening ...

  1. #1
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115

    Question reading and writing to files in windows

    Hi all,
    I am writting a windows app that read and writes files using the common dialog boxes for opening a file and saving the file.
    I was just wondering which is the best way to read and write bianary files in a windows program. I know how to do it the 'C' way, and c++ fstream way as well as using a handle and CreateFile(), but I want to know which way is better and why(if anyone knows or has a link please post )
    Any info is greatly appreciated.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    All intermediate file access mechanisms implemented in Win32, whether it be OpenFile, fopen, fstream, Win16 _lopen, etc., all ultimately call CreateFile. The following functions cover much of the work in opening files:


    CreateFile
    ReadFile
    WriteFile
    SetFilePointer
    SetEndOfFile
    CloseHandle

  3. #3
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Thanks for the info poccil. I will look those functions up in the help files.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    All of them work. The C way, the C++ way, the WinAPI. The best API is the API you know well enough not to make any mistakes.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    hehehe to true. That is why I went the fstream route, I know it better and had a less chance of messing it up
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Generally speaking I don't use CreateFile() unless I really need to optimize disk IO. I think that is a good rule of thumb.

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    I find WinAPI a very messy, inconsistent hulk of mostly obsolete code. I prefer not to use it when possible.

  8. #8
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    So what do you use? MFC? I want to learn both better because API lets you see what is happening but MFC is much quicker to use for Development
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    MFC provides CFile class for file operations.
    Chintan R Naik

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading and writing files
    By jcafaro10 in forum C Programming
    Replies: 8
    Last Post: 04-08-2009, 11:36 PM
  2. writing and reading files
    By oldie in forum C Programming
    Replies: 1
    Last Post: 07-03-2008, 05:54 PM
  3. reading and writing to files
    By cgod in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2004, 11:00 PM
  4. Reading and Writing from files
    By dutch's finest in forum C Programming
    Replies: 8
    Last Post: 03-18-2004, 04:34 AM
  5. Reading binary files and writing as text
    By thenrkst in forum C++ Programming
    Replies: 8
    Last Post: 03-13-2003, 10:47 PM

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