Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Reading/writing files on Windows

I have a question regarding using files in C++ on Windows platform. There are two ways the file operations could be performed: using C++ fstream (or derived) classes or using Windows API. Which way is better, why, and on which occasions?

Comments

  • stephlstephl Member Posts: 422
    : I have a question regarding using files in C++ on Windows platform. There are two ways the file operations could be performed: using C++ fstream (or derived) classes or using Windows API. Which way is better, why, and on which occasions?
    :

    Well, I'm not an expert, but I think one advantage of the use of the Windows API functions is to specify more options for the file (security, share mode and so on).

    Steph
  • stoberstober Member Posts: 9,765 ✭✭✭
    : : I have a question regarding using files in C++ on Windows platform. There are two ways the file operations could be performed: using C++ fstream (or derived) classes or using Windows API. Which way is better, why, and on which occasions?
    : :
    :

    depends on what you want to do. c++ fstream class is portable to any operating system. So if you need portability then use it. If you need to work with huge files you may be forced to use win32 api functions or do something that fstream does not support (very rare occurence). I think fstream file size is limited to 2 Gig. win32 api functions can work with files much much larger than that (whatever the limit of a 64-bit unsigned integer is).
  • zibadianzibadian Member Posts: 6,349
    : : : I have a question regarding using files in C++ on Windows platform. There are two ways the file operations could be performed: using C++ fstream (or derived) classes or using Windows API. Which way is better, why, and on which occasions?
    : : :
    : :
    :
    : depends on what you want to do. c++ fstream class is portable to
    : any operating system. So if you need portability then use it. If
    : you need to work with huge files you may be forced to use win32 api
    : functions or do something that fstream does not support (very rare
    : occurence). I think fstream file size is limited to 2 Gig. win32
    : api functions can work with files much much larger than that
    : (whatever the limit of a 64-bit unsigned integer is).

    The upper limit of such an integer is about 2 Exabyte (2*10^18 bytes).
Sign In or Register to comment.