C++ : Read/Write Binary data to file when data is complex -


how write/read data file in binary, if have define how save data?
i'm attempting save simple data structures out file in binary.

for example, have vector of structs this:

struct vertex {     x;     y;     z; }  std::vector<vertex> vertices; 

i want save vector out file in binary.

i know how output using ifstream , ostream using << , >> operators, can overloaded handle data, can't output binary.

i know how use .write() write in binary, issue there can't find way overload need, in order handle data.

here answer similar question. while ok in case, aware if using pointers in struct, not work.

the pointer means : "there relevant data loaded in other memory segment", really, contains address of memory. write operation save memory location. when load back, there little chance memory still holds information want.

what people create serialization mechanism. add method struct, or write function takes struct parameter , outputs char* array containing data in special format decide. need opposite function read file , recreate struct binary data. should take @ boost::serialization handles common programming problem.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -