Portable File Class

Environment: any ANSI C++-compilant compiler.

Overview

A common way of dealing with file I/O in the Windows environment is utilizing MFC's CFile class. But what if you, a professional win32 programmer, are having trouble in programming file operations under Linux, Solaris, or another UNIX system? What if you just don't want to mess with those heavyweight MFC classes?

If your answer is "YES!!!" then the portable 'File' class is a cure for all your diseases.

Advantages

  • The 'File' class utilizes ANSI C++ I/O functions only (I hope.), so it is absolutely portable. There should be no problem in using it on a variety of platforms.
  • Works faster and consumes less memory than MFC's CFile.
  • Class interface is identical to MFC's CFile.
  • Look at the documentation (PortableFileClass.hpp file) for some advanced routines.

Disadvantages

  • The 'File' class is missing routines that deal with file status.
  • Rough changing of file size is not yet implemented.
  • Error handling is not perfect yet...

Usage

  • #include file "PortableFileClass.hpp" to your application's main .cpp file.
  • Declare:

      File myFileObject;

    where myFileObject is a placeholder for the name of your file object.
  • PortableFileClass.hpp file cantains all the required documentation—look at the very beginning of a file.
  • Enjoy.

Good luck!

Downloads

Download demo project - 1.7 Kb
Download source - 3.2 Kb


Comments

  • Buffering

    Posted by Legacy on 08/14/2002 12:00am

    Originally posted by: Gregs

    One of the main reasons to use C functions instead of the C++ streams is the fact the the streams use buffering that can affect the timing of file transactions, especially writing. Buffering can cause the output not to be written if the program crashes, which would affect any logging or debug streams.

    Reply
  • Why???

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: musti

    C++ has its own *portable* file input and output stream classes (like fstream, ifstream and ofstream) which are very fast and useful. Why should someone use this class instead of using the built-in classes of C++?

    Reply
  • Reimplementing the wheel...

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: Paul A. Howes

    I don't want you to think that your portable CFile class is not good, because it is! You put a lot of work into writing and documenting the class, and it shows.

    However, you should be aware that in C, the standard "fopen", "fclose", etc. are very portable, and in C++, std::fstream and its bretheren are fast, robust, and a part of the ISO C++ standard.

    Reply
  • Why???

    Posted by Legacy on 08/13/2002 12:00am

    Originally posted by: musti

    C++ has its own *portable* file input and output stream classes (like fstream, ifstream and ofstream) which are very fast and useful. Why should someone use this class instead of using the built-in classes of C++?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds