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: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 29, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this eSeminar, Gene Kim will discuss these survey findings and will share woeful tales of artifact management gone wrong! Gene will also share examples of how …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds