I ultimately need to read in a binary file of unsigned ints into a matrix. The goal is to manipulate this matrix and extract a submatrix. (The binary is a 3D image and I want to make a separate file with some arbitrary chunk of the image)
I first read the file into a memory block and now I want to put this into the matrix (210x210x1000).
Is it possible to use the std::vector? Do I need to use a for loop and fill each matrix element, parsing the memory block by the size of an unsigned int?
Do I need to use a for loop and fill each matrix element, parsing the memory block by the size of an unsigned int?
It depends on the format of the data in the file. If the file is a sequence of int's, written by the same kind of computer, you can read the block as you're doing now. You'll need to set the size of the vector before the read.
1 2 3 4
//... get size of file and open file
Now, that's equivalent to what you've done with the memblock.