Calculate file size

This is a discussion on Calculate file size within the C++ Programming forums, part of the General Programming Boards category; How can we calculate text file size in bytes? Using VC++!...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    38

    Calculate file size

    How can we calculate text file size in bytes? Using VC++!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int GetFileSize(const std::string& FileName)
    {
      int Size;
      std::ifstream File;
    
      File.open(FileName.c_str(), std::ios::in | std::ios::binary);
      if(File.fail()) return -1;
    
      File.seekg(0, std::ios::end);
      Size = File.tellg();
    
      File.close();
      return Size;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21