That is the point. How to write and read binary files with std::vector inside them?
I was thinking something like:
//============ WRITING A VECTOR IN
Before reading vector
, you should resize it: yourVector.size(numberOfElementsYouRead)
.
Besides, sizeof(vector
is just the size of the vector
object internal implementation; vector element size is sizeof(std::vector
.
Then read it like this:
file.read(reinterpret_cast(&myVector[0]), sizeof(vector::element_type) * element_count);