Results 1 to 5 of 5

Thread: Getting file length with fstream?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    109

    Getting file length with fstream?

    Ok... I'm opening up a file using fstream class.... but once its open.... how do i get the file size/length? In good 'ol VB there was the "LOF" ... but I'm not seeing any member functions in the fstream class that get the file length.
    Code:
    	fstream file;
    
    	file.open("C:\\file.txt", ios::in | ios::binary, filebuf::sh_none);
    	char *buff = new char[LOF];
    	file.read(buff, LOF);
    	file.close();
    but i want to replace the LOF's with "file.LOF()" or however im supposed to get the file length..

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    109
    oh come on, someones gotta know!

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    fstream file;
    
    file.open("C:\\file.txt", ios::in | ios::binary, filebuf::sh_none);
    file.seekg(SEEK_END, 0);
    
    char *buff = new char[file.tellg()];
    
    file.seekg(SEEK_SET, 0);
    
    file.read(buff, LOF);
    file.close();
    ...or something
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    109
    Ya, I ended up figuring it out..... mine looks very similar to yours......

    Code:
    	file.open("C:\\file.txt", ios::in | ios::binary, filebuf::sh_none);
    	file.seekg(0, ios::end);
    	LOF = file.tellg();
    	file.seekg(0, ios::beg);
    	//char *buff = new char[LOF];
    	//file.read(buff, LOF);
    	file.close();
    	//delete [] buff;

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Whoops, messed up on the SEEK_SET...those are for fseek in the C Library, sorry

    The ios::* ones are right...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width