i have some Problem reading a 2D Vector from a binary File:
For Example:
My Binary File is structured like this :
243524
764756
746384
Now i want to create a 2D Vector which looks exactly like the bin File.
What i've done so Far:
I created a 1D Vector which contains all Elements. Then i created a Loop and filled the 2D Vector.
My Problem ist that i have a huge .bin File and the for loop cost a lot of Time. is there a possibility to get the 2DVector faster ?
My Code :
ifstream file("C:\\XXX.bin", ios::in | ios::binary | ios::ate);
char * buffer;
long size;
file.seekg(0, std::ios::end);
size = file.tellg();
buffer = new char[size];
file.read(buffer, size);
file.close();
double* double_values = (double*)buffer;//reinterpret as doubles
vector<double> buffer2(double_values, double_values + (size / sizeof(double)));
//cout << "Filling matrix with test numbers.";
int h = 0;
for (int i = 0; i < (size / sizeof(double)) / row; i++)
{
vector<double> temp;
for (int j = 0; j < row; j++)
{
if (h<size / sizeof(double))
{
temp.push_back(buffer2[h]);
h++;
}
}
bin_file.push_back(temp);
}
Hope that sb can Help me :)
operator(). That should help to speed up the reading as you can read the whole file into a single vector.vector, but easily modified to usevector).