Reading in 4 bytes at a time
Posted
by alphomega
on Stack Overflow
See other posts from Stack Overflow
or by alphomega
Published on 2010-06-04T13:40:48Z
Indexed on
2010/06/06
18:22 UTC
Read the original article
Hit count: 257
c++
I have a big file full of integers that I'm loading in. I've just started using C++, and I'm trying out the filestream stuff. From everything I've read, it appears I can only read in bytes, So I've had to set up a char array, and then cast it as a int pointer.
Is there a way I can read in 4 bytes at a time, and eliminate the need for the char array?
const int HRSIZE = 129951336; //The size of the table
char bhr[HRSIZE]; //The table
int *dwhr;
int main()
{
ifstream fstr;
/* load the handranks.dat file */
std::cout << "Loading table.dat...\n";
fstr.open("table.dat");
fstr.read(bhr, HRSIZE);
fstr.close();
dwhr = (int *) bhr;
}
© Stack Overflow or respective owner