07-27-2003, 07:27 PM
Sorry for asking this here, but I'm stuck, and you guys seem to know a lot. I've tried getting help on comp.lang.c++ newsgroup, but haven't had much luck.
What I'm trying to do is test some ideas for hash functions I've been toying with. I'm having problem with file I/O.
What I want to to is:
1) open a file
2) determine it's length so that I determine the number of pad bytes I'll need
3) dump the file to memory and pad as needed.
4) access the padded file in memory as an array of unsigned long.
My problems are 1--I don't know how to find the size of the file.
if I do:
fstream in("myfile.dat");
cout << sizeof(in);
the reported size is different than the size on disk. (I think white spaces are stripped in the fstream).
if I load the file into a char array, then I can't access the array as an array of unsigned int.
I'm thinking that I need to do something like:
ifstream in("myfile.dat");
stringstream inmem;
inmem << in.rdbuf();
//pad inmem
//send inmem to properly sized array using inmem.read()
However, when I compare:
sizeof(in)
and
sizeof(inmem)
I get 2 different values...neither of which match the size on disk of myfile.dat!!!
Any suggestions?? thanks.
What I'm trying to do is test some ideas for hash functions I've been toying with. I'm having problem with file I/O.
What I want to to is:
1) open a file
2) determine it's length so that I determine the number of pad bytes I'll need
3) dump the file to memory and pad as needed.
4) access the padded file in memory as an array of unsigned long.
My problems are 1--I don't know how to find the size of the file.
if I do:
fstream in("myfile.dat");
cout << sizeof(in);
the reported size is different than the size on disk. (I think white spaces are stripped in the fstream).
if I load the file into a char array, then I can't access the array as an array of unsigned int.
I'm thinking that I need to do something like:
ifstream in("myfile.dat");
stringstream inmem;
inmem << in.rdbuf();
//pad inmem
//send inmem to properly sized array using inmem.read()
However, when I compare:
sizeof(in)
and
sizeof(inmem)
I get 2 different values...neither of which match the size on disk of myfile.dat!!!
Any suggestions?? thanks.