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

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds