Menu

Sending IFSTREAM Classes to Functions

2002-08-23
2012-09-26
  • Nobody/Anonymous

    Theres a problem sending a file to a function in console applications for me; you may help me! I have included <fstream.h> and <iostream.h> and declared a variable by ifstream file. Now theres a function whose prototype reads as follows:
    void countfile (, ifstream &file,);
    This functions tries to read all the characters of file and performs some task. The effect of calling countfile(, file,)  is that cout (or anything like it, such as printf) doesnt work!

    Thanks for reply

     
    • Nobody/Anonymous

      Hi there,

      This may be of some use to you. =)

      Kip

      /*
         Name: getFileSize()
         Author: Kip Warner
         Description: Returns the file size of pszFileName in bytes. -1 on error...
      */

      int getFileSize(char *pszFileName)
      {
          // Variables...
          int nFileSize = 0;
          FILE *someFile;

          // Open the file...
          someFile = fopen(pszFileName, "r");

          // Check for error...
          if(!someFile)
              return -1;

          // Get file size...
          fseek(someFile, 0, SEEK_END);
          nFileSize = ftell(someFile);

          // Close stream...
          fclose(someFile);

          // Return file size...
          return nFileSize;
      }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.