Thread: File Length

  1. #1
    Registered User
    Join Date
    Apr 2002

    File Length

    How do you determine the length of a file without manually traversing it from the beginning and looking for eof?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    file.seekg ( 0, ios::end );
    int size = file.tellg();

    My best code is written with the delete key.

  3. #3
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    or if you are using handles, you can use filelength (), and if you need a translation from streams you can do filelength ( fileno (stream));
    hasafraggin shizigishin oppashigger...

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    If you are using Preulde's method you need to besure to open the file in binary mode or else the new line characters and other things can mess up the size.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM