I want to read binary file and store data into 3D float array. I've seen some examples for 1D array, but don't know how to expand it to 3D.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int N = 1024;
// allocate 3d array
float *** stmp = (float ***)malloc(N * sizeof(float**));
for (int i = 0; i < N; i++) {
stmp[i] = (float **)malloc(N * sizeof(float *));
for (int j = 0; j < N; j++) {
stmp[i][j] = (float *)malloc(N * sizeof(float));
}
}
string path = "Velocity1_inertHIT.bin";
ifstream infile;
infile.open(path);
return 0;
}
std::vectorinstead of this C-stylemalloc()mess. You probably don't want a 3D array, but an array of sizeN*N*Nand then use emulation to access the elements.