|
-
Jul 26th, 2002, 06:24 PM
#1
Thread Starter
Lively Member
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..
-
Jul 28th, 2002, 02:34 AM
#2
Thread Starter
Lively Member
oh come on, someones gotta know!
-
Jul 28th, 2002, 04:22 AM
#3
Monday Morning Lunatic
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
-
Jul 29th, 2002, 05:49 AM
#4
Thread Starter
Lively Member
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;
-
Jul 29th, 2002, 11:51 AM
#5
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|