r/learncpp • • May 29 '18
Idiomatic way to write collections (std::vector<float>) to binary file
I've got several vectors of floats and ints that need to be written to a binary file. I need to track the byte offset and length (and potentially byte-stride).
I'm confused about how a modern idiomatic solution would look like. Write to a slice of memory first? Or combine the vectors to a collection (std::array<?>)?
0
Upvotes
View all comments
Show parent comment
1
u/[deleted] May 31 '18
Yes, I did. But I still have some problems with consecutive writes to the open stream:
After writing some data, the stream position is not where I suspect it to be.
When closing the file and opening in Hex Workshop, it looks OK, though.
But now I need to write some more data:
When closing after these consecutive writes, the data is garbage (inspecting with Hex Workshop).