Question

Hmm, hello! I am trying to read a binary file that contains a number of float values at a specific position. As seemingly must be done with binary files, they were saved as arrays of bytes, and I have been searching for a way to convert them back to floats with no success. Basically I have a char* memory block, and am attempting to extract the floats stored at a particular location and seamlessly insert them into a vector. I wonder, would that be possible, or would I be forced to rely on arrays instead if I wished to save copying the data? And how could it possibly be done? Thank you ^_^

Was it helpful?

Solution

If you know where the floats are you can read them back:

float a = *(float*)buffer[position];

Then you can do whatever you need of a, including 'push_back'ing it into a vector.

Make sure you read the file in binary mode, and if you know the positions of the float in the file it should work.

I'd need to see the code that generated the file to be more efficient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top