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: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds