vector serialization

后端 未结 4 728
挽巷
挽巷 2020-12-19 06:44

I am trying to binary serialize the data of vector. In this sample below I serialize to a string, and then deserialize back to a vector, but do not get the same data I start

4条回答
  •  有刺的猬
    2020-12-19 06:53

    strncpy is a giant pile of fail. It will terminate early on your input because the size_t have some zero bytes, which it interprets as the NULL terminator, leaving them as default-constructed 0. If you ran this test on a BE machine, all would be 0. Use std::copy.

提交回复
热议问题