I have a vector aVector
. It starts at some memory address, let it be 0x00cff87f
in this case.
I also have a double D
.
Now, when the program accesses the D
above, it accesses some other address, of course.
What I need is that when the program accesses D
above, to be pointed to address 0x00cff87f
, the start of that array, and take the first sizeof(double)
bytes as a double.
I tried passing pointer to D
to a function and switch it, but that just changed where that pointer was pointing at, once I exited the function, D
remained unchanged.
Basically, I need some way to tell the program that four bytes of memory starting at 0x00cff87f
are a double and that when I ask for a double named D
to get me the number at that address.
I have an array in memory that needs to be decomposed to basic types, but instead of copying everything unnecessarily, I'd rather just tell the program where it already is.
How do I do that?
EDIT:
I have a vector of unsigned chars that I want to read into other types. Something that C# BinaryReader
would do with MemoryStream
. I don't know how to do it in c++. There are only fstreams, there isn't one that deals with (binary) files already in memory.