I am trying to make a simple program that will read
a file like a matrix of ints.
The idea is that there is a binary file with ints:
1 2 3 4 5 6 7 8 9
and I want to read them in a buffer 3 ints at a time, and then print
them sepparated by spaces. Then I want to read then next 3 integers.
However when I try the reinterpret cast on a buffer of 12 chars.. I
get into problems. Any help appreciated.
I have this so far:
const static int BUF_SIZE = 4; // 4 * num of ints
int main(int argc, char** argv)
ios_base::in | ios_base::binary);
while (file.read(&buf, BUF_SIZE))
for (uint32_t i = 0; i < 3; ++i)
uint32_t *num = reinterpret_cast<uint32_t* >(&buf);
std::cout << (uint32_t) *num << " ";
std::cout << std::endl;