Reading a binary file like a matrix of ints
I would like to read a binary file as quickly as possible. Right now I am reading integer by integer, but that could end up being slow.. I imagine, it is probably best to put it all in a big buffer, but then I don't know how to convert that to an array of integers.
so far this is a snippet of the code I have:
Any help appreciated,
ios_base::in | ios_base::binary);
char buf[BUF_SIZE]; //BUF_SIZE is 4
while (file.read(reinterpret_cast<char*>(&buf), sizeof(uint32_t)))
uint32_t *num = reinterpret_cast<uint32_t* >(&buf);
std::cout << left << setw(10) << *num << " ";
std::cout << endl;
what if the buffer isn't completely full?
How could I tell that the buffer is completely full or more like when it isn't completely full as there were no 1000 numbers, how can I prevent myself from accessing garbage locations?